Data Grid Jump to last page load whole data

Ok, I’ve done some testing. Slicing cause to load the data too for the search iterator. So it’s not really an improvement.

But I have a really strange solution to the problem :slight_smile:.
I still need to find a way to show the showed “last” page in the right order. Now it’s too reversed. So each showed page in that mode need to be reordered.

Instruction

  1. add a hidden label to control the custom buttons
  2. create custom buttons for the pagination control
    image
  3. make changes to your server call function to react on jump to last page button differently if the total length of you list is for e.g. over 1500 rows.

How it works:

  • instead of jumping to the last page and loading the data. It make a database call to get the reverse order than it is now
  • with the hidden label, I control my if statement how the buttons will work
  • at the end it iterates from back but the number of page of pages should make you think otherwise :slight_smile:
  • I need only to find a way to reverse the order o the showed rows only (now it’s showing it reversed)

Custom button jump to the last page

  def last_page_click(self, **event_args):
    """This method is called when the button is clicked"""
    if self.total.text > 1500:
      database = anvil.server.call('get_sample_database_reverse')#modified function to force reverse ordert than it is now
      self.repeating_panel_assay.items = database#set new database with reverse order
      self.table_order.text = 'reverse'#to controll the rest of the custom pagination buttons
      self.page.text = self.pageof.text#set to last page#the counter page of pages to set the page to the last number
    else:#standard controll
      self.data_grid_assay.jump_to_last_page()
      self.page.text = int(self.data_grid_assay.get_page())+1

Custom button for previous page:

  def previous_click(self, **event_args):
    """This method is called when the button is clicked"""
    if self.table_order.text == 'reverse':
      self.data_grid_assay.next_page()
      self.page.text -= 1
      self.select_all.checked = False#reset check all to unselect
    else:
      self.data_grid_assay.previous_page()
      self.page.text = int(self.data_grid_assay.get_page())+1
      self.select_all.checked = False#reset check all to unselect

same changes need to be applied for next page and jumpt to the first page to reverse the process.

on the server side, the function that controls it need to take your query and how you order your table in consideration to work. I did for the test only a simple version without any additional query functions.

@anvil.server.callable
def get_sample_database_reverse():
  "fetch the basic data of samples"
  database = app_tables.sample_database.search(q.fetch_only("barcode", "study_id","name","status","matrix","ext_barcode",
                                                            "volume","order_number","comment",updated_by=q.fetch_only("email")),tables.order_by("barcode", ascending=False))
  return database