From 20c31cbb076eb676c7e8105e626bf22ac8634133 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 25 Sep 2020 16:05:07 -0500 Subject: [PATCH] Fix grid bug when paginator is not involved --- tailbone/grids/core.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 442568de..a6672270 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -1194,8 +1194,16 @@ class Grid(object): status_map = {} checked = [] + # we check for 'all' method and if so, assume we have a Query; + # otherwise we assume it's something we can use len() with, which could + # be a list or a Paginator + if hasattr(raw_data, 'all'): + count = raw_data.count() + else: + count = len(raw_data) + # iterate over data rows - for i in range(len(raw_data)): + for i in range(count): rowobj = raw_data[i] row = {} @@ -1262,6 +1270,8 @@ class Grid(object): results['pages'] = self.pager.page_count results['first_item'] = self.pager.first_item results['last_item'] = self.pager.last_item + else: + results['total_items'] = count return results