fix: move "searchable columns" grid feature to wuttaweb
This commit is contained in:
parent
1d00fe994a
commit
ffa724ef37
|
@ -200,7 +200,6 @@ class Grid(WuttaGrid):
|
||||||
filterable=False,
|
filterable=False,
|
||||||
filters={},
|
filters={},
|
||||||
use_byte_string_filters=False,
|
use_byte_string_filters=False,
|
||||||
searchable={},
|
|
||||||
checkboxes=False,
|
checkboxes=False,
|
||||||
checked=None,
|
checked=None,
|
||||||
check_handler=None,
|
check_handler=None,
|
||||||
|
@ -254,6 +253,12 @@ class Grid(WuttaGrid):
|
||||||
DeprecationWarning, stacklevel=2)
|
DeprecationWarning, stacklevel=2)
|
||||||
kwargs.setdefault('page', kwargs.pop('default_page'))
|
kwargs.setdefault('page', kwargs.pop('default_page'))
|
||||||
|
|
||||||
|
if 'searchable' in kwargs:
|
||||||
|
warnings.warn("searchable param is deprecated for Grid(); "
|
||||||
|
"please use searchable_columns param instead",
|
||||||
|
DeprecationWarning, stacklevel=2)
|
||||||
|
kwargs.setdefault('searchable_columns', kwargs.pop('searchable'))
|
||||||
|
|
||||||
# TODO: this should not be needed once all templates correctly
|
# TODO: this should not be needed once all templates correctly
|
||||||
# reference grid.vue_component etc.
|
# reference grid.vue_component etc.
|
||||||
kwargs.setdefault('vue_tagname', 'tailbone-grid')
|
kwargs.setdefault('vue_tagname', 'tailbone-grid')
|
||||||
|
@ -287,8 +292,6 @@ class Grid(WuttaGrid):
|
||||||
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.checkboxes = checkboxes
|
self.checkboxes = checkboxes
|
||||||
self.checked = checked
|
self.checked = checked
|
||||||
if self.checked is None:
|
if self.checked is None:
|
||||||
|
@ -481,15 +484,6 @@ class Grid(WuttaGrid):
|
||||||
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)
|
||||||
|
|
||||||
|
@ -1587,6 +1581,7 @@ class Grid(WuttaGrid):
|
||||||
'field': name,
|
'field': name,
|
||||||
'label': self.get_label(name),
|
'label': self.get_label(name),
|
||||||
'sortable': self.is_sortable(name),
|
'sortable': self.is_sortable(name),
|
||||||
|
'searchable': self.is_searchable(name),
|
||||||
'visible': name not in self.invisible,
|
'visible': name not in self.invisible,
|
||||||
})
|
})
|
||||||
return columns
|
return columns
|
||||||
|
|
|
@ -136,10 +136,8 @@
|
||||||
<${b}-table-column field="${column['field']}"
|
<${b}-table-column field="${column['field']}"
|
||||||
label="${column['label']}"
|
label="${column['label']}"
|
||||||
v-slot="props"
|
v-slot="props"
|
||||||
:sortable="${json.dumps(column.get('sortable', False))}"
|
:sortable="${json.dumps(column.get('sortable', False))|n}"
|
||||||
% if hasattr(grid, 'is_searchable') and grid.is_searchable(column['field']):
|
:searchable="${json.dumps(column.get('searchable', False))|n}"
|
||||||
searchable
|
|
||||||
% endif
|
|
||||||
cell-class="c_${column['field']}"
|
cell-class="c_${column['field']}"
|
||||||
:visible="${json.dumps(column.get('visible', True))}">
|
:visible="${json.dumps(column.get('visible', True))}">
|
||||||
% if hasattr(grid, 'raw_renderers') and column['field'] in grid.raw_renderers:
|
% if hasattr(grid, 'raw_renderers') and column['field'] in grid.raw_renderers:
|
||||||
|
|
|
@ -57,6 +57,12 @@ class TestGrid(WebTestCase):
|
||||||
grid = self.make_grid(default_page=42)
|
grid = self.make_grid(default_page=42)
|
||||||
self.assertEqual(grid.page, 42)
|
self.assertEqual(grid.page, 42)
|
||||||
|
|
||||||
|
# searchable
|
||||||
|
grid = self.make_grid()
|
||||||
|
self.assertEqual(grid.searchable_columns, set())
|
||||||
|
grid = self.make_grid(searchable={'foo': True})
|
||||||
|
self.assertEqual(grid.searchable_columns, {'foo'})
|
||||||
|
|
||||||
def test_vue_tagname(self):
|
def test_vue_tagname(self):
|
||||||
|
|
||||||
# default
|
# default
|
||||||
|
|
Loading…
Reference in a new issue