3
0
Fork 0

Compare commits

...

2 commits

Author SHA1 Message Date
Lance Edgar 9541407978 bump: version 0.21.1 → 0.21.2 2025-02-18 16:33:59 -06:00
Lance Edgar 80aae74907 fix: add hidden flag for grid columns
sometimes a column is rendered such that its data cannot be used for
other component logic.  in which case, can add a hidden column to pass
the raw data, for component use
2025-02-18 16:31:25 -06:00
5 changed files with 91 additions and 14 deletions

View file

@ -5,6 +5,12 @@ All notable changes to wuttaweb will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## v0.21.2 (2025-02-18)
### Fix
- add hidden flag for grid columns
## v0.21.1 (2025-02-17)
### Fix

View file

@ -6,7 +6,7 @@ build-backend = "hatchling.build"
[project]
name = "WuttaWeb"
version = "0.21.1"
version = "0.21.2"
description = "Web App for Wutta Framework"
readme = "README.md"
authors = [{name = "Lance Edgar", email = "lance@wuttaproject.org"}]

View file

@ -156,6 +156,15 @@ class Grid:
See also :meth:`set_link()` and :meth:`is_linked()`.
.. attribute:: hidden_columns
List of column names which should be hidden from view.
Hidden columns are sometimes useful to pass "extra" data into
the grid, for use by other component logic etc.
See also :meth:`set_hidden()` and :meth:`is_hidden()`.
.. attribute:: sortable
Boolean indicating whether *any* column sorting is allowed for
@ -372,6 +381,7 @@ class Grid:
row_class=None,
actions=[],
linked_columns=[],
hidden_columns=[],
sortable=False,
sort_multiple=True,
sort_on_backend=True,
@ -399,6 +409,7 @@ class Grid:
self.row_class = row_class
self.actions = actions or []
self.linked_columns = linked_columns or []
self.hidden_columns = hidden_columns or []
self.joiners = joiners or {}
self.config = self.request.wutta_config
@ -535,6 +546,43 @@ class Grid:
if key in self.columns:
self.columns.remove(key)
def set_hidden(self, key, hidden=True):
"""
Set/override the hidden flag for a column.
Hidden columns are sometimes useful to pass "extra" data into
the grid, for use by other component logic etc.
See also :meth:`is_hidden()`; the list is tracked via
:attr:`hidden_columns`.
:param key: Column key as string.
:param hidden: Flag indicating whether column should be hidden
(vs. shown).
"""
if hidden:
if key not in self.hidden_columns:
self.hidden_columns.append(key)
else: # un-hide
if self.hidden_columns and key in self.hidden_columns:
self.hidden_columns.remove(key)
def is_hidden(self, key):
"""
Returns boolean indicating if the column is hidden from view.
See also :meth:`set_hidden()` and :attr:`hidden_columns`.
:param key: Column key as string.
:rtype: bool
"""
if self.hidden_columns:
if key in self.hidden_columns:
return True
return False
def set_label(self, key, label, column_only=False):
"""
Set/override the label for a column.
@ -2090,6 +2138,7 @@ class Grid:
columns.append({
'field': name,
'label': self.get_label(name),
'hidden': self.is_hidden(name),
'sortable': self.is_sortable(name),
'searchable': self.is_searchable(name),
})

View file

@ -165,19 +165,21 @@
>
% for column in grid.get_vue_columns():
<${b}-table-column field="${column['field']}"
label="${column['label']}"
v-slot="props"
:sortable="${json.dumps(column.get('sortable', False))|n}"
:searchable="${json.dumps(column.get('searchable', False))|n}"
cell-class="c_${column['field']}">
% if grid.is_linked(column['field']):
<a :href="props.row._action_url_view"
v-html="props.row.${column['field']}" />
% else:
<span v-html="props.row.${column['field']}"></span>
% endif
</${b}-table-column>
% if not column['hidden']:
<${b}-table-column field="${column['field']}"
label="${column['label']}"
v-slot="props"
:sortable="${json.dumps(column.get('sortable', False))|n}"
:searchable="${json.dumps(column.get('searchable', False))|n}"
cell-class="c_${column['field']}">
% if grid.is_linked(column['field']):
<a :href="props.row._action_url_view"
v-html="props.row.${column['field']}" />
% else:
<span v-html="props.row.${column['field']}"></span>
% endif
</${b}-table-column>
% endif
% endfor
% if grid.actions:

View file

@ -281,6 +281,26 @@ class TestGrid(WebTestCase):
self.assertFalse(grid.is_linked('foo'))
self.assertTrue(grid.is_linked('bar'))
def test_hidden_columns(self):
grid = self.make_grid(columns=['foo', 'bar'])
self.assertEqual(grid.hidden_columns, [])
self.assertFalse(grid.is_hidden('foo'))
grid.set_hidden('foo')
self.assertEqual(grid.hidden_columns, ['foo'])
self.assertTrue(grid.is_hidden('foo'))
self.assertFalse(grid.is_hidden('bar'))
grid.set_hidden('bar')
self.assertEqual(grid.hidden_columns, ['foo', 'bar'])
self.assertTrue(grid.is_hidden('foo'))
self.assertTrue(grid.is_hidden('bar'))
grid.set_hidden('foo', False)
self.assertEqual(grid.hidden_columns, ['bar'])
self.assertFalse(grid.is_hidden('foo'))
self.assertTrue(grid.is_hidden('bar'))
def test_searchable_columns(self):
grid = self.make_grid(columns=['foo', 'bar'])
self.assertEqual(grid.searchable_columns, set())