Events
Event names and payload types are in the API reference under GridEvents, and the subscribe methods under GridApi.
Subscribe and unsubscribe
on and once return a function that unsubscribes.
const off = api.on('rowClicked', ({ row, rowKey, rowIndex, event }) => {
console.log(rowKey, rowIndex, row);
});
off();Events that start in the DOM, such as rowClicked, carry the original MouseEvent as event. If a handler throws, the other handlers of the same event still run, and the exception is logged with console.error. You can subscribe or unsubscribe while an event is being dispatched.
Click a row, a cell or a header to see the payloads.
Receive every event in one place
const off = api.onAny((name, payload) => console.log(name, payload));
off();onAny receives every event except error, in the order they happen (1.3.5). An exception from your handler is reported as callback-error on the error event. Use it to feed a log panel or an external event bus.
Wire events in each framework
Pass on<Name> props. The grid does not resubscribe when a handler changes; it calls the latest one.
<Grid options={options} onRowClicked={({ rowKey }) => console.log(rowKey)} />Event list
| Event | Payload |
|---|---|
ready | { api }. Fires in a microtask right after creation |
destroyed | {} |
optionsChanged | { changed }. Names of the options that changed |
rowsChanged | { reason, count }. reason is set, add, update, remove or transaction |
transactionsFlushed | { transactions, added, updated, removed }. Once after the changes collected by transactBatched were applied |
columnsChanged | { columns } |
rowClicked, rowDoubleClicked | { row, rowKey, rowIndex, event } |
cellClicked, cellDoubleClicked | { row, rowKey, rowIndex, columnId, value, event, zone? }. Row number and state cells have an empty columnId and zone rownum or state |
bodyClicked, bodyDoubleClicked | { x, y }. A click on the empty body below or beside the rows. Grid-local coordinates (px, origin at the top left, scale applied). Not sent for rows, headers, summary rows, the pager or popups. Empty grids count too (1.5.0) |
editInput | { rowKey, columnId, value }. Every time the input text changes. value is the text before parsing and validation. Only text, number, percent, mask, textarea, combobox, remote and stepper (1.5.0) |
headerClicked | { columnId, event, zone? }. Row number and state headers have an empty columnId and zone rownum-header or state-header |
headerFocused | { columnId }. When header focus changes; null when cleared (1.3.6) |
contextMenuRequested | { zone, rowKey, columnId, x, y, event }. Before a menu opens (1.3.6) |
cellLongPressed | { rowKey, columnId, x, y }. A long press by touch (1.3.6) |
cellMouseOver, cellMouseOut, cellMouseDown | { rowKey, columnId, event }. Active only while subscribed (1.3.6) |
headerMouseOver, headerMouseOut | { columnId, event }. Active only while subscribed (1.3.6) |
cellMenuOpened, cellMenuClosed | { rowKey, columnId } (1.3.6) |
columnMenuOpened, columnMenuClosed | { columnId } (1.3.6) |
noMatches | {}. Once when rows exist but none are visible; fires again after rows show up (1.3.6) |
firstRendered | { rowCount }. Once, when the first rows are drawn. Active only when subscribed (1.4.0) |
gridResized | { width, height }. When the size really changes, once per frame. Active only when subscribed (1.4.0) |
viewportChanged | { first, last }. When the range of visible row indexes changes. Active only when subscribed (1.4.0) |
scrollEnded | { top, left }. Once, events.scrollEndMs (default 150 ms) after the last scroll. Active only when subscribed (1.4.0) |
columnsVirtualChanged | { first, last }. When the drawn column window changes. Active only when subscribed (1.4.0) |
modelChanged | { reasons }. One event per tick for model changes. Reasons: rows sort filter quickFilter group tree page options columns (1.4.0) |
rowSelected | { key, selected }. One per changed key, before selectionChanged (1.4.0) |
diagnostic | { kind, code, message, where? }. Mirrors every error. kind is error or notice (1.4.0) |
pinnedRowsChanged | { top, bottom }. Keys of pinned data rows (not external rows). When pinRow, unpinRow or a row removal changes the pins (1.4.0) |
summaryCellClicked, summaryCellDoubleClicked | { rowId, columnId, scope, key, event }. A click on a total or subtotal cell. scope is grid or group. No row or selection events (1.4.0) |
sortChanged | { sortModel } |
filterChanged | { filterModel } |
scrolled | { top, left }. Only when the scroll position changes |
selectionChanged | { selectedKeys }. Only when the selection changes. See Row selection |
focusChanged | { rowKey, columnId }. Both are null when no cell is focused |
editStarted | { rowKey, columnId, trigger, startKey? } |
editCommitted | { rowKey, columnId, oldValue, newValue }. Only when the value changed |
editCancelled | { rowKey, columnId, reason } |
validationFailed | { rowKey, columnId, value, message }. See Cell editing |
changesCountChanged | { count, added, modified, removed, saving }. When the counts or the saving state change |
batchStarted | {}. When the first change appears in an empty change list (1.3.5) |
batchEnded | { reason, count }. When the change list becomes empty again. reason is commit, rollback, accept or revert (1.3.5) |
rowsSoftRemoved | { keys, mode }. When rows were only marked as removed with removeMode. mode is hide or mark (1.3.5) |
rowsRestored | { keys }. When a removed mark was cleared and the rows came back (1.3.5) |
editRequested | { rowKey, columnId, value, oldValue, apply, reject }. Instead of committing when editApply is 'app' (1.3.5) |
editRejected | { rowKey, columnId, value, message }. When the app calls reject() (1.3.5) |
bulkEditStarted | {}. After beginBulkEdit() (1.3.5) |
bulkEditEnded | { count, committed }. After endBulkEdit(). count is the number of writes (1.3.5) |
stateChanged | { part }. After one part of the view state (columns sort filter groupBy page selection) changed (1.3.5) |
saveStarted | { saveId, changes }. Just before the handler runs |
saveFailed | { saveId, error, changes, failed }. A handler exception or a partial failure |
changesCommitted | { changes }. Changes that were confirmed, including saved rows |
changesRolledBack | { changes }. Changes that were rolled back |
error | { code, message, cause, where, cell? }. cell only where the cell is known (1.4.0). See Error handling |
When you no longer need the grid, call destroy(). It fires destroyed and removes all listeners. The wrappers call it for you when the component goes away.
Event order
When one action produces several events, the table below gives the order they go out in. A hook, if present, runs first and can veto the action; when it does not, the change happens and then the events go out. The table is checked by a test that runs the real flows and records the order, so it cannot drift from the code.
| Flow | Order |
|---|---|
| Click a cell (row selection on) | cellMouseDown → focusChanged → rowSelected → selectionChanged → rowClicked → cellClicked |
| Double-click a cell, type, press Enter | cellMouseDown → focusChanged → rowSelected → selectionChanged → rowClicked → cellClicked → cellMouseDown → rowClicked → cellClicked → beforeEdit (hook) → editStarted → rowDoubleClicked → cellDoubleClicked → editInput → transformEdit (hook) → batchStarted → changesCountChanged → rowsChanged → editCommitted → historyChanged |
| Change the sort | sortChanged |
| Change the filter | filterChanged → focusChanged |
| Add rows | beforeAddRows (hook) → changesCountChanged → rowsChanged |
| Remove rows | beforeRemoveRows (hook) → historyChanged → changesCountChanged → rowsChanged |
| Move a column | beforeColumnChange (hook) → columnMoved |
| Resize a column | beforeColumnChange (hook) → columnResized |
- The table leaves out screen and state notices such as
firstRendered,viewportChanged,scrolled,stateChangedandmodelChanged. They may appear in between, so do not assume their position. - A double-click sends
rowDoubleClickedandcellDoubleClickedafter the edit has started. cellMouseDownworks only when subscribed and goes out before thefocusChangedof the same click.- Row-number and state cells and summary rows send their own events instead of row and cell events (the
zonevalues andsummaryCell*in the list above).
View events
firstRendered, gridResized, viewportChanged, scrollEnded and columnsVirtualChanged create their observers and timers only when you subscribe. With no subscriber there is no DOM observer and no timer, and dropping the last subscription or calling destroy() removes them all. Values that change often, like size and scroll, are reported at most once per frame and only when the value really changed.
api.on('viewportChanged', ({ first, last }) => console.log(`visible rows ${first}-${last}`));
api.on('scrollEnded', ({ top }) => saveScroll(top)); // after 150 ms without scrolling
// events: { scrollEndMs: 300 } changes the time (0-2000)firstRendered fires once when the first rows are drawn. If data arrives later it fires then, and if you subscribe after rows are already drawn it fires right away. rowSelected fires once per changed key just before selectionChanged (a select-all sends one per key). diagnostic folds the error event and the notice codes into one stream.
Cancel and transform hooks
Since 1.3.4
The hooks option is available from 1.3.4.
Events tell you after something happened; a hook runs before it and can stop it or change a value. Pass only the hooks you need as functions in the option hooks. Hooks you leave out do nothing.
createGrid(el, {
columns,
rows,
hooks: {
beforeRemoveRows: ({ keys }) => confirm(`Delete ${keys.length} rows?`), // false: nothing is deleted
beforeEdit: ({ columnId }) => columnId !== 'id', // false: the editor does not open
transformEdit: ({ value }) => (typeof value === 'string' ? value.trim() : undefined),
},
});| Hook | Called | Return value |
|---|---|---|
beforeAddRows({ rows, source }) | addRows call | false cancels |
beforeRemoveRows({ keys, source }) | removeRows call | false cancels, returns 0 |
beforeColumnChange({ type, columnId }) | hide, show, move, pin, unpin, resize of a column | false cancels |
beforeSort({ model, source }) | just before the sort model changes (1.5.0) | false cancels |
beforeFilter({ model, source }) | just before the filter model changes (1.5.0) | false cancels |
beforeGroup({ columns, op, source }) | just before the grouping changes (1.5.0) | false cancels |
beforePageChange({ from, to, pageSize, source }) | just before the page changes (1.5.0) | false cancels |
beforeExpand({ keys, kind, source }) | just before a tree or group opens (1.5.0) | false cancels |
beforeCollapse({ keys, kind, source }) | just before a tree or group closes (1.5.0) | false cancels |
beforeEdit({ rowKey, columnId, value, trigger }) | just before the editor opens | false keeps it closed |
transformEdit({ rowKey, columnId, value, oldValue }) | on commit, before validation | final value; undefined keeps it |
onKeyDown({ event, rowKey, columnId, editing }) | key press inside the grid | true: the grid ignores the key |
canSelect({ kind, rowKey, columnId }) | row or cell selection | false blocks it |
beforeUndo(), beforeRedo() | undo, redo | false does nothing |
rowRendered({ rowKey, element, index }) | a row element is filled (also when scrolling reuses it) | none |
- A blocked action changes no state, emits no event and adds nothing to the undo history.
- If a hook throws, the action is allowed and one
errorevent (code: 'callback-error',where: 'hooks.<name>') is emitted. - If the same hook is called again while it is running (a hook that calls an API which triggers it), the second call is skipped and allowed.
- The row hooks and the column hooks run for requests from code and from the screen. Writes that feature modules make internally,
setColumnStateandresetColumnStateare not asked. - The six 1.5.0 hooks (
beforeSort,beforeFilter,beforeGroup,beforePageChange,beforeExpand,beforeCollapse):sourceis'user'for gestures (header click, filter popup, pager, expand arrow, group panel, menus) and'api'for code calls- Not asked: initial options,
setViewStateandinitialStaterestore, the resetssetRowsdoes, server paging total updates, expansion reasonsrevealanddata - They run only when the model really changes. The same value is not asked again.
expandAll,collapseAllandexpandToDepthcall the hook once withkeys: 'all', and a veto cancels the whole call (depth 0 uses the collapse hook).- A vetoed gesture produces no event and no state change. A code call returns without an exception (the return value does not change).
- The
modelofbeforeSortandbeforeFilteris the new model. Clearing the filter sends a model with no items.
- While a column is being resized by dragging,
beforeColumnChangeis called on every move. Keep it light. - The edit order is
beforeEdit-> editor ->transformEdit-> validation -> commit. See Editing cells and Row selection.