From ec2600ddf7179276849e970d7beb43498d21313e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 26 Feb 2022 21:00:05 -0600 Subject: [PATCH] Add simple searchable column support for non-AJAX grids idk maybe even AJAX grids can use? not gonna try at the moment --- tailbone/grids/core.py | 12 ++++++++++++ tailbone/templates/grids/buefy.mako | 5 ++++- tailbone/views/email.py | 3 +++ tailbone/views/tables.py | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index bc7c6684..75c2ffd5 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -76,6 +76,7 @@ class Grid(object): enums={}, labels={}, assume_local_times=False, renderers={}, invisible=[], extra_row_class=None, linked_columns=[], url='#', 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, checkboxes=False, checked=None, check_handler=None, check_all_handler=None, @@ -119,6 +120,8 @@ class Grid(object): self.use_byte_string_filters = use_byte_string_filters self.filters = self.make_filters(filters) + self.searchable = searchable or {} + self.sortable = sortable self.sorters = self.make_sorters(sorters) self.default_sortkey = default_sortkey @@ -241,6 +244,15 @@ class Grid(object): kwargs['label'] = self.labels[key] self.filters[key] = self.make_filter(key, *args, **kwargs) + def set_searchable(self, key, searchable=True): + if searchable: + self.searchable[key] = True + else: + self.searchable.pop(key, None) + + def is_searchable(self, key): + return self.searchable.get(key, False) + def remove_filter(self, key): self.filters.pop(key, None) diff --git a/tailbone/templates/grids/buefy.mako b/tailbone/templates/grids/buefy.mako index 5ef15a17..0801bbe8 100644 --- a/tailbone/templates/grids/buefy.mako +++ b/tailbone/templates/grids/buefy.mako @@ -187,6 +187,9 @@ % if grid.is_linked(column['field']): @@ -217,7 +220,7 @@ % endif -