From cb6499522eb697a5d35db0563896f737740f2c3b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 14 Jun 2022 11:25:29 -0500 Subject: [PATCH] Let default grid page size correspond to first option --- tailbone/grids/core.py | 11 +++++++++-- tailbone/views/master.py | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 7bc0c01d..0e2833dc 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -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(): diff --git a/tailbone/views/master.py b/tailbone/views/master.py index e7dc7c64..fe77c7b5 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -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()