Column Menu
Open the header column menu from the header menu button, by right-clicking any leaf header, or via keyboard (Shift+F10, Alt+Down, or ContextMenu) without scrolling the viewport.
import { Grid, type ColumnDef } from 'next-grid-js';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';
export function mount({ stage, meta }: DemoMountContext): () => void { const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, isSortable: true, }, { key: 'customer', name: 'Customer', width: 180, flex: 1, isSortable: true, }, { key: 'region', name: 'Region', width: 115, isSortable: true, }, { key: 'amount', name: 'Amount', width: 120, cellDataType: 'number', isSortable: true, formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, { key: 'status', name: 'Status', width: 110, isSortable: true, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: createOrders(25), getRowId: (row) => row.id, columnMenu: { getMenuItems: ({ params, defaultItems }) => [ ...defaultItems.filter((item) => item.id !== 'reset'), { kind: 'separator' }, { kind: 'custom', name: `Log "${params.colId}" width`, action: ({ column }) => { meta.textContent = `${column.colId}: ${Math.round(column.width)}px`; }, }, ], }, }); const stopTheme = syncGridTheme(stage); meta.textContent = 'Right-click any header or open the menu icon';
return () => { grid.destroy(); stopTheme(); };}Built-in Action IDs (ColumnMenuBuiltinId)
Section titled “Built-in Action IDs (ColumnMenuBuiltinId)”| ID | Behavior | Disabled When |
|---|---|---|
'sort-asc' / 'sort-desc' |
Sort ascending or descending | Non-client source or isSortable: false |
'clear-sort' |
Remove sort from this column | Column is not sorted or non-sortable |
'hide' |
Hide the current column | Only one visible column remains |
'show-all' |
Show all hidden columns | All columns are already visible |
'pin-start' / 'pin-end' |
Pin to logical start or end | Already pinned there or violates minCenterWidth |
'unpin' |
Unpin column back to center | Column is not pinned |
'autosize' |
Autosize this column | isResizable: false |
'fit' |
Scale eligible center columns to fit viewport | No resizable center columns |
'reset' |
Reset all columns to columnDefs defaults |
Never |
Customizing (getItems vs. getMenuItems)
Section titled “Customizing (getItems vs. getMenuItems)”Set at most one of getItems or getMenuItems (setting both throws at construction), or pass columnMenu: false to disable the header menu:
getItems(params): Appends synchronous custom items after the 11 defaults (an empty result keeps the defaults).getMenuItems({ params, defaultItems }): Returns the complete list of{ kind: 'builtin', id, name? },{ kind: 'custom', name, isDisabled?, action }, and{ kind: 'separator' }items. Passnameon a built-in item to override its label. Returning an empty array[]preserves the native browser menu on right-click.- Limits: Maximum
64total items and32custom items;actioncallbacks must be synchronous.