What I’m trying to do:
- I want to use custom_component or another form as item_template with data grid
- Also i want to use pagination and display certain number of rows per page
What’s wrong
Pagination and data_grid.rows_per_page
is not working as expected when repeating_panel.item_template = CustomForm
. When custom template is set datagrid displays all the rows.
Pagination and data_grid.rows_per_page
is working as expected when using the row template that is automatically created from the editor
What I’ve tried and what’s not working:

Result:
Clone link:
https://anvil.works/build#clone:YG2C4TORIWTQIPWQ=MWZNI6BKWRW6V3J6EBFPTKBF
That’s weird, I don’t understand why the pagination doesn’t work with a custom template. Perhaps the RowTemplate does something under the hood that interact with the pagination.
But… why are you trying to use a custom template?
I make all sort of things like adding canvas with graphics, buttons, custom components to my data grid templates, and the pagination works just fine.
I always start from a RowTemplate and add to it.
If I want the whole row clickable I start by disabling the auto_display_data
, adding a link, a datarow panel inside the link, set databinding for its item
to self.item
and add to it. Adding a datarow allows to manage the column widths defined in the datagrid.
Sometimes I add both a datarow with some components inside, so they are aligned with the datagrid columns, then I add other components under the datagrid where I’m free to do whatever I want. Adding a canvas with some graphics makes them look really cool.
Yeah, It is weird. Also, It was working as expected before beta editor came out.
I have custom templates of several models on a separte package called “Templates”
That way i can use the same template in multiple location/pages/data_grids. If i need to chnage something i can just change in one place.
Other than reusability i dont have any other good reason to use custom templates!
Well that’s a pretty good reason.
Perhaps you can make reusable row templates, but if it was working in the past, it should work now.
Have you tried switching to the old editor and create a new app?
This is expected behaviour.
The DataGrid → RepeatingPanel → DataRowPanel setup works together to do pagination and layout.
A CustomForm (BlankPanel) doesn’t know how to do pagination and layout inside a DataGrid and so doesn’t end up contributing to the pagination.
In the design view, isolated reusable RowTemplates are tricky since they are typically coupled to the DataGrid they are nested within. You can reuse RowTemplates but only if the DataGrids have the same column structure (Or you are only ever using auto_display=True
with no other complexity)
(This isn’t new and the Beta editor hasn’t changed this behaviour. If you have a previous working implementation it’s likely that the custom template was actually a row template).
You’ve probably read this already but some more details about datagrids in the docs.
I found a workaround to reuse CustomForm as templates and do pagination.
Here’s how i did it,
repeating_panel.tag.custom_template = CustomForm
and then from inside default row_template i check if self.parent (repeating_panel) has a tag with CustomForm
if yes,
self.clear()
self.add_component(CustomForm(item=self.item))
CustomForm is now inside the DataRowPanel, everything works!
But, It would be great if ColumnPanel/BlankPanel also followed the pagination mechanism.
Have you tried putting the custom form inside the row template, ad I suggested earlier?
1 Like
Yes, that’s exactly what i am doing. I have the auto generated default row template, then I am putting the custom template inside the row template during runtime.
I have a rather complex template and i’m just too lazy to redo it with a DataRowPanel
I wish there were an easy way to change/update parent container type.
i.e: Form inherits from ColumnPanel
if i could just change the type from ColumnPanel to DataRowPanel/FlowPanel without messing up inner components!
Why?
What is the problem with doing whatever you need to do inside a row template?
No problem! i am just too lazy to do it again! here is why,
Here is the form I want to use as a row template. It’s an entire page. I want to show only 1 row per page and leverage pagination to move around
if I copy everything from here and paste it inside a DataRowPanel, that messes up the way components are placed inside this form, also the events of my custom components are not copied along. So, I have to re-organize the componets, set event handlers for my custom componets, correct relative import paths… which may take only just 10-20 min, but feels tedious.
Thats why.
Have you tried dragging that form inside a row template?
1 Like
Wow! It feels like magic. I thought only custom components can be dragged n dropped, never even tried to drag n drop a form before.
1 Like