When setting the rows_per_page property of a datagrid in one of my forms, it shows all the items rather than the number I set. In a datagrid in a different form, the rows_per_page property works as expected.
any ideas about what might be wrong?
When setting the rows_per_page property of a datagrid in one of my forms, it shows all the items rather than the number I set. In a datagrid in a different form, the rows_per_page property works as expected.
any ideas about what might be wrong?
That happened to me, once. It turned out that I had code, elsewhere, which subsequently also set my grid’s rows_per_page
.
youre probably right. plot twist
how did you end up solving this?
I did a global search on rows_per_page
, to ensure that I was catching all the places in my code where I was setting it. I called print
at each of these places, each call printing something distinctive, so I could see which call(s) was actually being invoked, in what order.
Since I also use Git to get a local copy of the application files, I used that to extend my search into the form-layout files (.yaml files), to see if I had any overrides there (e.g., through Data Binding).
This showed me exactly what code was being called unintentionally. (It was some initialization code. I had forgotten that it even existed.)
That code was no longer needed, for anything, so removing it fixed my problem.
thanks for sharing. im not setting that parameter anywhere else in code. I do use the properties editor to set the number of rows, but none of those seem to be passing their rows_per_page value along. very strange…
How do your Data Bindings check out?
i wasnt using databindings. Only weird thing about this is that I am using a form from a different repeating panel item template as the repeating item in the datagrid.
One of my surprises, at one point, was that I was using a Data Binding, for a value, even though I hadn’t intended to.
It was a copy/paste/edit job, where the edit phase got interrupted. I had meant to edit out a value from the Data Bindings, and had code present to set the value. But both were being used.
it was something related to setting the item template to a form used in another repeating panel and having no columns in the datagrid. My solution was to create 1 column, add a column_panel to that column, and add the template form to the column panel.
This sounds an awful lot like a bug! Is it something repeatable? Anvil Support will want to have a look at it, I think.
I have been having the same problem in one of my apps. I cannot figure out if it is a bug or something I am missing. I quickly clicked through the creation of a very minimal example to show this.
Here I have a table with 8 rows and I am trying to display 2 rows per page:
https://anvil.works/build#clone:HG5B64NTKQ63X34H=UST6URIVRJHU2GMBIXVD2IG5
it seems to work if you use rows_per_page
in conjunction with a row_template
inside a repeating_panel
inside a data_grid
but not otherwise…
Yea agreed. I came to the same conclusion.
Unfortunately, the display that I would like to page through is a little complex, and it is tough to adapt a row_template
to it. My application would work easily if I could just use another form template (as I attempted in my example). The docs and the Anvil builder seem to indicate to me that this is possible and intended. However, I just can’t seem to get it to work…
Do you happen to know why this might be? Or have a workaround @stucork? Or is there a way to use a Form within a row_template
?
I was hoping to test out a suggestion made to me in this post:
Where I basically make a one row data grid to flip through a set of connected data tables that all link to one row of a single data table. The built-in pagination seemed like the overall combined cleanest / most efficient of the suggestions in that post for cycling through a data table in both directions.
The working for a row_template
but not a custom template may also explain the OP’s comment:
which is basically as we described. Could this be a bug?
Edit:
I somehow just noticed this:
which I think is maybe an adequate workaround solution. I am about to test it now.
For pagination to work, your DataGrid needs to understand how many rows of data there are in the child component. This system only works if the child component (i.e. RepeatingPanel’s ItemTemplate) inherits from DataRowPanel.
RowTemplates are Forms just like any other Form. All forms inherit from one of the standard Anvil containers (e.g. BlankPanel Forms inherit from ColumnPanel). RowTemplates are Forms that inherit from DataRowPanel, which enable them to integrate with DataGrid columns, perform pagination etc.
This is why rows_per_page
works when using a RowTemplate, but not if you use a BlankPanel Form - a RowTemplate inherits from DataRowPanel and can communicate with the DataGrid to tell it how many rows of data it contains.
If you’d rather use a BlankPanel Form inside your RepeatingPanel, you can add a BlankPanel Form to the RowTemplate, and then rows_per_page
will work. Here’s a modified version of the clone link you shared, using the RowTemplate, but adding ‘Form2’ to that RowTemplate:
https://anvil.works/build#clone:5MYFMYNH2SQMFUY3=WDFLGGKWRJAZ7DSXPGPGVD6P
Oooooo makes sense. Thanks a lot for the thorough explanation. I didn’t fully understand the structures.
I actually got it working yesterday (as per @joinlook’s hints) doing exactly as you described
and was going to reply back later today. However, I still wasn’t sure if this was a hackish solution or acceptable. It makes a lot of sense within context though. Thanks!