Header Menu
Use the tool property in column headers to add custom menus for filtering, column visibility, and other actions.
<Grid
controller={PageController}
records={m.filtered}
style="height: 300px;"
scrollable
border
emptyText="No records found matching the given criteria."
columns={[
{
header: {
text: "Name",
tool: columnMenu(
<TextField mod="menu" placeholder="Filter" value={m.filter.name} />,
),
},
field: "fullName",
sortable: true,
},
{
header: {
text: "Continent",
tool: checkboxFilterMenu("filter.continents"),
},
field: "continent",
visible: m.visibility.continent,
sortable: true,
},
{
header: {
text: "Browser",
tool: checkboxFilterMenu("filter.browsers"),
},
field: "browser",
visible: m.visibility.browser,
sortable: true,
},
{
header: "Visits",
field: "visits",
align: "right",
visible: m.visibility.visits,
sortable: true,
},
]}
/> | Name | Continent | Browser | Visits |
|---|---|---|---|
| Alice Johnson | Europe | Chrome | 45 |
| Bob Smith | Asia | Firefox | 23 |
| Carol White | North America | Safari | 67 |
| David Brown | Europe | Chrome | 12 |
| Eva Green | Asia | Edge | 89 |
Click the menu icon in any header to open the dropdown menu.
Adding a Header Tool
The tool property accepts any widget content that will be rendered in the header cell:
{
header: {
text: "Name",
tool: (
<Menu horizontal>
<Submenu placement="down-left">
<Icon name="menu" />
<Menu putInto="dropdown">
<TextField placeholder="Filter" value={m.filter.name} />
</Menu>
</Submenu>
</Menu>
),
},
field: "fullName",
}
Column Visibility
Combine header menus with the visible property to let users show/hide columns:
{
header: {
text: "Browser",
tool: columnMenu,
},
field: "browser",
visible: m.visibility.browser,
}
The menu can contain checkboxes bound to visibility state:
<Checkbox value={m.visibility.browser} mod="menu">
Browser
</Checkbox>
Tips
- Use
mod="menu"on form controls inside menus for proper styling. - Use
Submenuwithplacement="down-left"orplacement="down-right"to control dropdown direction. - Combine filtering with
addTriggerto automatically update displayed records when filters change.
See also: Complex Headers, Grid