CxJS

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 JohnsonEuropeChrome45
Bob SmithAsiaFirefox23
Carol WhiteNorth AmericaSafari67
David BrownEuropeChrome12
Eva GreenAsiaEdge89

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 Submenu with placement="down-left" or placement="down-right" to control dropdown direction.
  • Combine filtering with addTrigger to automatically update displayed records when filters change.

See also: Complex Headers, Grid