Skip to content

Column locks, show-when and roles ​

A few extra keys on a column definition change how that one column behaves. All are optional, and without them nothing changes. A value of the wrong shape throws invalid-option.

KeyWhat it does
lockedLock hiding, moving and pinning. true is all three; an object picks from { visible, position, pin }
showWhen'groupOpen' shows the column only while its header group is open, 'groupClosed' only while it is closed
cellRoleARIA role of body cells: 'gridcell' (default), 'cell', 'rowheader'
metaApp data. The grid never reads it; getColumns() returns it unchanged
notesfalse turns note actions off for that column

Locks ​

ts
columns: [
  { id: 'name', locked: { position: true } }, // cannot be moved by drag or API
  { id: 'id', locked: true }, // hiding, moving and pinning are all blocked
];
  • visible: the Hide item of the column menu is disabled, and setColumnVisible(id, false) throws invalid-option ("column is locked").
  • position: the header cannot be dragged, moved with Alt+arrows or moveColumn, and a move of another column that would push this column out of its place is silently ignored.
  • pin: the pin items of the column menu are disabled, and changing the pin state with pinColumn or pinColumns throws invalid-option. A call that keeps the current value passes.

setColumnState, initialState and view-state restore respect locks: a locked property keeps its current value and the rest of the saved state (width and so on) applies. No error is raised. Locked menu items are dimmed (aria-disabled) instead of removed, so the reason is visible.

Show by header group ​

ts
headerGroups: [{ id: 'pay', title: 'Pay', collapsible: true, children: ['base', 'bonus', 'total'] }],
columns: [
  { id: 'base' },
  { id: 'bonus', showWhen: 'groupOpen' }, // only while open
  { id: 'total', showWhen: 'groupClosed' }, // one total while closed
];

A group that has a showWhen column among its direct children is decided by these keys alone (columns without one are always shown). When the group closes, groupOpen columns hide; when it opens, groupClosed columns hide. If that would leave nothing visible, the first column stays. showWhen only works on a column inside a header group; otherwise it throws invalid-option. Use collapsible: true on the group for the toggle.

Style single cells ​

setCellStyle(rowKey, columnId, { className, style }) (1.5.0) layers a class and styles on one cell. Pass null to remove it. Entries are kept by row key and column id, so they follow the cell through sort, filter, paging and grouping.

MethodWhat it does
setCellStyle(rowKey, columnId, style | null)Set or remove the style of one cell
getCellStyle(rowKey, columnId)A copy of the stored style, or null
setCellStyles(entries)Many cells at once (one repaint, all or nothing)
clearCellStyles({ rowKeys?, columnIds? })Remove the matching cells, all of them without arguments
  • style follows the cellStyle callback rules: values are strings or numbers, and display, gridColumn and gridRow cannot be used.
  • Order: the cellClass, cellClassRules and cellStyle callbacks come first and this map last, so the map wins on a clash. Removing an entry brings back the callback value.
  • Unknown rows or columns and malformed values raise invalid-option. setCellStyles checks everything before applying.
  • Removing a row removes its entries. setRows keeps the entries of rows whose key is still there.
  • In memory only: not part of getViewState, no event, and export is unaffected.

Role, app data and notes ​

  • cellRole: 'rowheader' is for a cell that names its row, such as the first column. Screen readers announce it as a row header.
  • meta attaches your own data (source, permission) to a column. Read it with getColumns() inside callbacks such as columnMenu.items.
  • A column with notes: false drops the note items from the cell menu and ignores Shift+F2. Existing notes still show and getCellNote is unchanged.