Let default grid page size correspond to first option

This commit is contained in:
Lance Edgar 2022-06-14 11:25:29 -05:00
parent 78a9ba5084
commit cb6499522e
2 changed files with 13 additions and 4 deletions

View file

@ -78,7 +78,7 @@ class Grid(object):
joiners={}, filterable=False, filters={}, use_byte_string_filters=False,
searchable={},
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
pageable=False, default_pagesize=20, default_page=1,
pageable=False, default_pagesize=None, default_page=1,
checkboxes=False, checked=None, check_handler=None, check_all_handler=None,
clicking_row_checks_box=False, click_handlers=None,
main_actions=[], more_actions=[], delete_speedbump=False,
@ -618,6 +618,13 @@ class Grid(object):
keyfunc = lambda v: v[key]
return lambda q, d: sorted(q, key=keyfunc, reverse=d == 'desc')
def get_default_pagesize(self):
if self.default_pagesize:
return self.default_pagesize
options = self.get_pagesize_options()
return options[0]
def load_settings(self, store=True):
"""
Load current/effective settings for the grid, from the request query
@ -635,7 +642,7 @@ class Grid(object):
settings['sortkey'] = self.default_sortkey
settings['sortdir'] = self.default_sortdir
if self.pageable:
settings['pagesize'] = self.default_pagesize
settings['pagesize'] = self.get_default_pagesize()
settings['page'] = self.default_page
if self.filterable:
for filtr in self.iter_filters():

View file

@ -176,7 +176,7 @@ class MasterView(View):
rows_deletable = False
rows_deletable_speedbump = True
rows_bulk_deletable = False
rows_default_pagesize = 20
rows_default_pagesize = None
rows_downloadable_csv = False
rows_downloadable_xlsx = False
@ -523,11 +523,13 @@ class MasterView(View):
'use_byte_string_filters': self.use_byte_string_filters,
'sortable': self.rows_sortable,
'pageable': self.rows_pageable,
'default_pagesize': self.rows_default_pagesize,
'extra_row_class': self.row_grid_extra_class,
'url': lambda obj: self.get_row_action_url('view', obj),
}
if self.rows_default_pagesize:
defaults['default_pagesize'] = self.rows_default_pagesize
if self.has_rows and 'main_actions' not in defaults:
actions = []
use_buefy = self.get_use_buefy()