On this page
@addTagHelper *, Webority.Ui.RazorAbove a table
Put the Columns menu in a table's toolbar, so a person can hide the columns they do not need.
Hide the Owner or Floors column
A table with a Columns menu; unticking a column hides it, and the choice survives a reload.
| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
| Server Room | Asha Rao | 1 | Draft |
| Canteen Block | Meera Iyer | 2 | Compliant |
The view hook
Keep a table's hidden columns and sort in the browser with one hook, so the view survives a reload.
Remember columns and sort
The useTableView call shown as code, with its hiddenColumns and toggleColumn outputs.
Every option
Every value of every prop, one cell each.
columns: the hideable columns
columns: two optional columns| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
columns: one optional column| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
columns: no optional column| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
hiddenColumns: which columns are shown
hiddenColumns: none (default)| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
hiddenColumns: owner hidden, reached by unticking Owner in the menu| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
hiddenColumns: owner and floors hidden, reached by unticking both in the menu| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
onToggle: the callback
onToggle: no attribute, the Razor menu hides and shows the columns itself| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
label: the button name
label="Columns" (default)| Building | Owner |
|---|---|
| Corporate Office | Asha Rao |
label="Choose columns"| Building | Owner |
|---|---|
| Corporate Office | Asha Rao |
className: extra classes on the menu panel
className: React only, extra classes on the menu panel; the Razor menu takes none| Building | Owner |
|---|---|
| Corporate Office | Asha Rao |
for: the linked table
for: the linked table's id; React passes columns and hiddenColumns instead| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
view-key: the remembered view
view-key left off (default): nothing remembered; React's useTableView always remembers| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
view-key="column-menu-matrix": the choice is remembered in this browser| Building | Owner | Floors | Status |
|---|---|---|---|
| Corporate Office | Asha Rao | 12 | Draft |
| Warehouse Annexe | Vikram Shah | 3 | Compliant |
Guidance
What to do, and what to avoid.
Use it when
- A table has columns that only some people need, such as an owner, a created date or an internal code.
- People return to the same table and expect it the way they left it.
- The columns that identify a row must stay visible while the rest are optional.
Reach for something else when
- The table has only a few columns that all matter. → no menu
- You want to narrow which rows show. → AppTableToolbar
- You want the table in a different order. → AppDataTable
One Columns button in the toolbar
Do
One Columns button in the toolbar actions, beside search and export.
Avoid
A permanent row of checkboxes takes space above the table and pushes the data down.
Reference
Try every prop, read the full list, and check keyboard and screen reader behaviour.
7 props. The 2 most used come first.
Used on most screens 2 props
| Prop | Type | Default | Description |
|---|---|---|---|
| labeldefault Columns | string | Columns | Accessible name and tooltip of the button, and the menu heading. |
| hiddenColumnsdefault - | string[] | - | Razor reads the hidden columns from the remembered view; there is no attribute. |
Less common 5 props
| Prop | Type | Default | Description |
|---|---|---|---|
| fordefault - | string | - | The id of the <app-data-table> whose columns this menu controls. |
| view-keydefault - | string | - | Names the remembered view, stored in this browser under wui-view:<view-key>. Leave it off to remember nothing. |
| th data-keydefault - | string | - | On a <th> in the linked table: the column's name in the menu and in the remembered view. |
| th data-hideabledefault - | boolean | - | On a <th> that also has data-key: adds a checkbox for the column. |
| onToggledefault - | (key) => void | - | The Razor menu hides and shows the columns itself. |
Screen reader
2 notes- The button's accessible name and tooltip is the label prop.
- Each hideable column is a native checkbox inside a label, so its name is the column heading and Space toggles it.
Do and avoid
1 pairsOne Columns button in the toolbar
Do
One Columns button in the toolbar actions, beside search and export.
Avoid
A permanent row of checkboxes takes space above the table and pushes the data down.