Showing the previous page when updating datagrid items

If you populate a DataGrid, then click the pager buttons to go to the second page, then update the DataGrid’s RepeatingPanel’s items, the DataGrid goes back to the first page.

The following function allows to update the items in a DataGrid’s RepeatingPanel while preserving the current page, but… using a for cycle just doesn’t feel right.

Is there a better way?

def update_data_grid(self, repeating_panel, items):
  grid = repeating_panel.parent
  page = grid.get_page()
  repeating_panel.items = items
  for _ in range(page):
    grid.next_page()
2 Likes

There’s also a set_page() method. This was missing from the api docs and autocompleter for some reason - but it should be there now.

def update_data_grid(self, repeating_panel, items):
  grid = repeating_panel.parent
  page = grid.get_page()
  repeating_panel.items = items
  grid.set_page(page)
3 Likes