Hi Anvillistas!
Just sharing a technique you might want to use if you have a lot of columns in a Data Grid.
You can assign a few custom CSS rules to the Data Grid to make it have a horizontal scrollbar.
In this example, we’ve created a Role called wide
, so assigning that to the Data Grid gives it a CSS class named anvil-role-wide
.
.anvil-role-wide .data-grid-child-panel {
overflow-x: auto;
}
.anvil-role-wide .anvil-data-row-panel {
flex-wrap: nowrap;
min-width: -moz-min-content;
min-width: min-content;
}
(A good place to put these rules is theme.css
in the Assets.)
You also need to assign widths to each of your columns.
Here it is in action:
You might find it useful to assign the Role at runtime so that all columns of the Data Grid are displayed in the design view:
class Form1(Form1Template):
def __init__(self, **properties):
# ...
self.data_grid_1.role = 'wide'
Here’s a clone link for an app that has this implemented:
https://anvil.works/ide#clone:KTBKQJMLCATI3PPH=UUYFIYM3ZZB25VM6NRKDAONG
Shaun