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.
| Key | What it does |
|---|---|
locked | Lock 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 |
cellRole | ARIA role of body cells: 'gridcell' (default), 'cell', 'rowheader' |
meta | App data. The grid never reads it; getColumns() returns it unchanged |
notes | false turns note actions off for that column |
Locks
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, andsetColumnVisible(id, false)throwsinvalid-option("column is locked").position: the header cannot be dragged, moved withAlt+arrows ormoveColumn, 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 withpinColumnorpinColumnsthrowsinvalid-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
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.
| Method | What 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 |
stylefollows thecellStylecallback rules: values are strings or numbers, anddisplay,gridColumnandgridRowcannot be used.- Order: the
cellClass,cellClassRulesandcellStylecallbacks 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.setCellStyleschecks everything before applying. - Removing a row removes its entries.
setRowskeeps 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.metaattaches your own data (source, permission) to a column. Read it withgetColumns()inside callbacks such ascolumnMenu.items.- A column with
notes: falsedrops the note items from the cell menu and ignoresShift+F2. Existing notes still show andgetCellNoteis unchanged.