Add simple searchable column support for non-AJAX grids

idk maybe even AJAX grids can use?  not gonna try at the moment
This commit is contained in:
Lance Edgar 2022-02-26 21:00:05 -06:00
parent 63fef16c37
commit ec2600ddf7
4 changed files with 22 additions and 2 deletions

View file

@ -76,6 +76,7 @@ class Grid(object):
enums={}, labels={}, assume_local_times=False, renderers={}, invisible=[], enums={}, labels={}, assume_local_times=False, renderers={}, invisible=[],
extra_row_class=None, linked_columns=[], url='#', extra_row_class=None, linked_columns=[], url='#',
joiners={}, filterable=False, filters={}, use_byte_string_filters=False, joiners={}, filterable=False, filters={}, use_byte_string_filters=False,
searchable={},
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc', sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
pageable=False, default_pagesize=20, default_page=1, pageable=False, default_pagesize=20, default_page=1,
checkboxes=False, checked=None, check_handler=None, check_all_handler=None, 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.use_byte_string_filters = use_byte_string_filters
self.filters = self.make_filters(filters) self.filters = self.make_filters(filters)
self.searchable = searchable or {}
self.sortable = sortable self.sortable = sortable
self.sorters = self.make_sorters(sorters) self.sorters = self.make_sorters(sorters)
self.default_sortkey = default_sortkey self.default_sortkey = default_sortkey
@ -241,6 +244,15 @@ class Grid(object):
kwargs['label'] = self.labels[key] kwargs['label'] = self.labels[key]
self.filters[key] = self.make_filter(key, *args, **kwargs) 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): def remove_filter(self, key):
self.filters.pop(key, None) self.filters.pop(key, None)

View file

@ -187,6 +187,9 @@
<b-table-column field="${column['field']}" <b-table-column field="${column['field']}"
label="${column['label']}" label="${column['label']}"
:sortable="${json.dumps(column['sortable'])}" :sortable="${json.dumps(column['sortable'])}"
% if grid.is_searchable(column['field']):
searchable
% endif
:visible="${json.dumps(column['visible'])}"> :visible="${json.dumps(column['visible'])}">
% if grid.is_linked(column['field']): % if grid.is_linked(column['field']):
<a :href="props.row._action_url_view" v-html="props.row.${column['field']}"></a> <a :href="props.row._action_url_view" v-html="props.row.${column['field']}"></a>
@ -217,7 +220,7 @@
% endif % endif
</template> </template>
<template slot="empty"> <template #empty>
<section class="section"> <section class="section">
<div class="content has-text-grey has-text-centered"> <div class="content has-text-grey has-text-centered">
<p> <p>

View file

@ -105,6 +105,9 @@ class EmailSettingView(MasterView):
g.set_link('key') g.set_link('key')
g.set_link('subject') g.set_link('subject')
g.set_searchable('key')
g.set_searchable('subject')
# to # to
g.set_renderer('to', self.render_to_short) g.set_renderer('to', self.render_to_short)
g.sorters['to'] = g.make_simple_sorter('to', foldcase=True) g.sorters['to'] = g.make_simple_sorter('to', foldcase=True)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2022 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -70,6 +70,8 @@ class TableView(MasterView):
g.sorters['row_count'] = g.make_simple_sorter('row_count') g.sorters['row_count'] = g.make_simple_sorter('row_count')
g.set_sort_defaults('name') g.set_sort_defaults('name')
g.set_searchable('name')
# TODO: deprecate / remove this # TODO: deprecate / remove this
TablesView = TableView TablesView = TableView