Issue With DataGrid and Lazy Generator Function

What I’m trying to do:
I am trying to lazy load data into a datagrid using a generator function which yields rows.

What I’ve tried and what’s not working:
I got the general idea working however when I combine it with a nested repeating panel inside each row of the datagrid I am running into an issue where the last row of each page is not rendered completly (misses the nested repeating panel). Additionaly the last row then gets repeated on the next page, this time including the nested repeating panel.

When removing the nested repeating panel it appears to work just fine.

EDIT
The issue also appers to happen when replacing the generator function with a simple function returning all rows.

So the issue might be somwhere with the nested RepeatingPanel inside the datagrid rows?

EDIT-2
Further Testing revealed, that the issue also does not happen when the just the last row does not contain a nested repeating panel.

Here is a Code Sample of how I am generating the rows:

 def lazy_items(self):

    page = 0
    page_size = self.data_grid_1.rows_per_page
    while True:
      # Compute data range with 1 extra row for pagination lookahead
      if page == 0:
        start_index = 0
      else:
        start_index = page * page_size + 1  # Skip overlapping row
      end_index = (page + 1) * page_size + 1  # Always fetch +1 row

      data = [{'column_1':f'row{idx}'} for idx in range(start_index,end_index)]
      if not data:
        break
      print("#"*20)
      print("#"*5,page,"#"*5, 'Rows:', len(data))
      print("#"*20)
      for row in data:
        print(row)
        yield row
      page += 1

  def form_show(self, **event_args):
   self.repeating_panel_1.items = self.lazy_items() 

Clone link:

A quick work around:
instead of putting the repeating panel inside the row template column
put a column panel inside the row template column
and then put the repeating panel inside the column panel

Datagrids can be a bit too clever for their own good in how they determine number of rows.
And it looks like the last repeating panel thinks it should hide itself because it’s over the 5 row limit per page page.

3 Likes

Awesome, Thanks for the workarround.