Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Above 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.
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
Server RoomAsha Rao1Draft
Canteen BlockMeera Iyer2Compliant
Show code
<app-table-toolbar>
    <app-table-toolbar-actions>
        <app-column-menu for="buildings" view-key="buildings"></app-column-menu>
    </app-table-toolbar-actions>
</app-table-toolbar>
<app-data-table id="buildings">
    <thead><tr>
        <th>Building</th>
        <th data-key="owner" data-hideable>Owner</th>
        <th data-key="floors" data-hideable>Floors</th>
    </tr></thead>
    …
</app-data-table>

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.
Show code
const { hiddenColumns, toggleColumn, sort, setSort } = useTableView("invoices", {
  sort: { key: "issued", dir: "desc" },
});

<app-column-menu for="invoices" view-key="invoices"></app-column-menu>

Every option

Every value of every prop, one cell each.

columns: the hideable columns

columns: two optional columns
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
columns: one optional column
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
columns: no optional column
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant

hiddenColumns: which columns are shown

hiddenColumns: none (default)
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
hiddenColumns: owner hidden, reached by unticking Owner in the menu
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
hiddenColumns: owner and floors hidden, reached by unticking both in the menu
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant

onToggle: the callback

onToggle: no attribute, the Razor menu hides and shows the columns itself
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant

label: the button name

label="Columns" (default)
BuildingOwner
Corporate OfficeAsha Rao
label="Choose columns"
BuildingOwner
Corporate OfficeAsha Rao

className: extra classes on the menu panel

className: React only, extra classes on the menu panel; the Razor menu takes none
BuildingOwner
Corporate OfficeAsha Rao

for: the linked table

for: the linked table's id; React passes columns and hiddenColumns instead
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant

view-key: the remembered view

view-key left off (default): nothing remembered; React's useTableView always remembers
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
view-key="column-menu-matrix": the choice is remembered in this browser
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant

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
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
Server RoomAsha Rao1Draft

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.

BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
Server RoomAsha Rao1Draft
React, generated from the controls
<AppColumnMenu
  columns={columns}
  hiddenColumns={view.hiddenColumns}
  onToggle={view.toggleColumn}
/>
Razor, the same props
<app-column-menu for="cm-pg" />
<app-data-table id="cm-pg">
    <thead><tr>…<th data-key="owner" data-hideable>Owner</th>…</tr></thead>
</app-data-table>

7 props. The 2 most used come first.

Used on most screens 2 props

PropTypeDefaultDescription
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

PropTypeDefaultDescription
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 pairs

One Columns button in the toolbar

Do
BuildingOwnerFloorsStatus
Corporate OfficeAsha Rao12Draft
Warehouse AnnexeVikram Shah3Compliant
Server RoomAsha Rao1Draft

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.