Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

Show/Hide rows and columns in Data Grids

Are you new here?

Anvil is a tool for building full-stack web apps with nothing but Python and a drag-and-drop designer. Learn more on our website, or sign up and try it yourself -- it's free!

Here’s how to show and hide columns and rows when using Anvil’s Data Grids.

The Expandable Stock Chart Grid example has a box for hiding/showing a row. This is simply done by setting the visible property of the row in question.

Hiding columns is done by modifying the Data Grid’s columns property. Assigning to this property sets what columns the Data Grid has. So to hide a column, remove a column from the list and assign the new list back to columns:

column = [c for c in self.data_grid_1.columns if c['title'] == 'Stock Price'][0]
self.hidden_columns.append(column)
self.data_grid_stocks.columns.remove(column)
self.data_grid_stocks.columns = self.data_grid_stocks.columns

To add it back, put it back into the columns list and re-assign the list:

column = [c for c in self.hidden_columns if c['title'] == 'Stock Price'][0]
self.hidden_columns.remove(column)
self.data_grid_stocks.columns.append(column)
self.data_grid_stocks.columns = self.data_grid_stocks.columns

For more details, check out the Data Grids tutorial.