Skip to content

Data and rows ​

Choose a row key ​

rowKey is the value that tells rows apart. Pass a property name or a function.

ts
const options: GridOptions<Employee> = {
  columns,
  rows,
  rowKey: 'id', // or (row) => `${row.org}-${row.no}`
};

A duplicate key throws duplicate-row-key. A key that is undefined, null or an object throws missing-row-key.

If you omit rowKey, each row object gets an automatic key. In that mode updateRows cannot recognize a new object as the same row. If you plan to update rows, set rowKey.

Add, update and remove rows ​

ts
api.addRows([{ id: 4, name: 'Mia Foster', department: 'Engineering' }]); // append
api.addRows([{ id: 5, name: 'Lucas Gray', department: 'Product' }], 0); // insert at the top
api.updateRows([{ id: 2, name: 'Emma Wilson', department: 'Product' }]); // replace the row with the same key
api.removeRows([1]); // remove by key
api.setRows(newRows); // replace everything
  • updateRows replaces a row whole. If you pass only some fields, the rest are gone.
  • updateRows and removeRows ignore keys they cannot find and return how many rows they handled.
  • setRows always applies, even when you pass the same array again. It counts as a new baseline, so unsaved changes are discarded.
  • getRows(), getRowCount() and getRowByKey(key) read the original rows, regardless of sorting and filtering. To read what is on screen, use the methods in Read the visible rows.

Since 1.2.0

Since 1.2.0, one removeRows or updateRows call is one undo step. addRows, transact and setRows are not steps. The full rules are in Undo row removal and updates.

Live demo — drawn by the real renderer

Since 1.3.5

Ask the change state of one row with getRowState(key), of a cell with isCellChanged(key, columnId), and of the rows in the store with getRowsWithState(). revertRows and revertCells (partial revert), acceptRows (confirm without saving) and applyChanges (sync two grids) are in Batch save.

Keep removed rows around ​

Since 1.3.5

removeMode, the mode of removeRows, restoreRows, purgeRemoved and getChanges({ includeDiscarded }) are available from 1.3.5. The default ('delete') deletes at once as before. 'hide' and 'mark' need change tracking (saveMode 'batch' or 'immediate'); with 'none' they throw invalid-option.

Set removeMode to keep removed rows until you save and to be able to bring them back.

ts
createGrid(el, { columns, rows, removeMode: 'mark' }); // 'delete' (default) | 'hide' | 'mark'

api.removeRows([3, 5]); // removes the way the option says
api.removeRows([7], { mode: 'hide' }); // another way for this call only
api.restoreRows([3]); // clear the mark; returns the number of rows restored
api.purgeRemoved([5]); // really delete marked rows from the store (all if omitted)
api.getChanges({ includeDiscarded: true }); // also rows that were added and then removed
Item'hide''mark'
ScreenNot among the visible rowsVisible, muted text with a strike-through (mxg-row-removed), aria-disabled
Edit, selectNot possibleNot possible (a selected row leaves the selection)
Aggregates, summary rowExcludedExcluded
Sort, groups, page countsExcludedIncluded
ExportExcludedExcluded
Validation (validateRows)SkippedSkipped
  • A marked row stays in the store: it is in getRows() and getRowCount(), and indexes and keys do not change. The change list has it as removed, and getRowState(key) is 'removed'. rowsChanged is emitted only when rows are really deleted; marking emits rowsSoftRemoved { keys, mode } and restoring emits rowsRestored { keys }.
  • Removing a row that was added always deletes it for real, whatever the mode. It only stays in getChanges({ includeDiscarded: true }) as discarded: true until commit or rollback.
  • A commit (commitChanges, a successful save) also deletes marked rows from the store; a rollback brings them all back. The save handler receives them as removed changes. Accepting a marked row with acceptRows deletes the row too.
  • purgeRemoved really deletes the marked rows but keeps the change record as removed, so the save handler still sees them.
  • A mark is one undo step: undo restores, redo marks again (a step is skipped if a commit already deleted the row).
  • hooks.beforeRemoveRows is called for marking too and receives ctx.mode ('hide' or 'mark'); a plain delete has no mode. Returning false changes nothing and returns 0.

Go back to a save point ​

createSavePoint() (1.5.0) keeps a deep copy of the current getRows() in memory. Later restoreSavePoint(id) brings that state back. It suits "try something and roll back if you do not like it" screens.

MethodWhat it does
createSavePoint(name?)Keeps a deep copy of the rows and returns { id, name, createdAt, rowCount }
restoreSavePoint(id, { keepView? })Replaces the rows with that copy
listSavePoints()The kept points, oldest first
deleteSavePoint(id), clearSavePoints()Remove one or all
Event savePointRestored{ id, name }, once after a restore
  • Ids look like sp-1, sp-2 and are never reused. Without a name, or with an empty or blank string, you get Save point 1. A value that is not a string raises invalid-option.
  • At most 20 are kept. Creating the 21st drops the oldest.
  • Plain objects, arrays, Date, Map and Set are copied. Functions and class instances are shared, not copied, and a diagnostic notice is sent once when a point holds such values.
  • Restoring goes through setRows with a fresh copy, so sort, filter, page, expansion and selection are cleared. With keepView: true they are kept as far as the keys still exist.
  • A restore clears change tracking and the undo history (as if freshly loaded). That differs from rollbackChanges and revertRows, which undo edits: Batch save.
  • Cell notes, cell styles and hidden rows are not in the copy. Save points live in memory only and are not part of getViewState.
  • A server row model (rowModel: 'infinite') cannot use them because the data is not in this grid (invalid-option). An unknown id is also invalid-option. The second argument of restoreSavePoint accepts only { keepView?: boolean }; an unknown key or a non-boolean value raises invalid-option.

Hide and show rows ​

hideRows(keys) (1.5.0) takes rows out of the view without removing them. You do not have to manage a filter, and showRows(keys?) shows them again (all when called without keys).

MethodWhat it does
hideRows(keys)Hide rows
showRows(keys?)Show hidden rows again, all without keys
getHiddenRows()The hidden keys (data order)
isRowHidden(key)Whether that key is hidden
Event rowsHiddenChanged{ keys, hidden }, only the keys that really changed
  • Like rows hidden by removeMode: 'hide', hidden rows are left out of sorting, grouping, aggregates, the summary, page counts, select all, find, export and getVisibleRows.
  • The rows stay in getRows(). Hiding is not a change, so it is not in change tracking or the undo history.
  • Hiding a tree parent hides its descendants too. The descendants' own hidden state does not change.
  • setRows keeps the entries whose key is still there, and removing a row removes its entry. When keys disappear, rowsHiddenChanged { keys, hidden: false } fires once per call.
  • Hiding a selected row (including tree descendants) removes it from the selection and fires selectionChanged once. Showing it again does not bring the selection back.
  • An unknown key raises invalid-option.
  • isRowFilteredOut(key) looks at the filter only. It is false for rows hidden with hideRows (rows hidden by a soft removal stay true as before). Read hiding with isRowHidden.
  • The 1.4.0 option grouping.hideRows is a different feature. It stops drawing the group header lines and does not hide data rows.

Merge server rows by key ​

To combine rows freshly received from a server with what is on screen, use mergeRows instead of replacing everything with setRows. Rows with the same key are replaced and unknown keys are added. The change is a new baseline, so it does not appear in change tracking.

ts
const report = api.mergeRows(serverRows, { conflict: 'mine' });
// { added, updated, overwritten, kept, skipped }

When a row has unsaved changes or a cell is being edited, conflict decides.

conflictCells you edited / the cell being edited
'server' (default)The server wins. The row's unsaved changes are dropped and the edit is cancelled
'mine'Your edited cells are kept and the rest take the server value. The server value is the new baseline
'notify'Kept like 'mine', and cells whose values differ are reported by mergeConflict

A row you added but have not saved is left alone with 'mine' and 'notify', and a row you deleted does not come back. The same key twice in the input changes nothing and throws invalid-option. Rows that disappeared from the server are removed with removeRows.

See the example

Write cell values from code ​

Three methods write cell values without replacing whole rows.

ts
api.setCellValue(2, 'owner', 'Mina'); // one cell: true when it changed
api.setCellValue(2, 'hours', 99, { validate: true }); // false and nothing written if a column rule fails
api.fillColumn('priority', 'high'); // one column on every row
api.fillColumn('priority', 'high', { scope: 'visible' }); // only the data lines currently visible
api.updateCells([1, 2, 3], { owner: 'Dan', hours: 8 }); // several columns on several rows
  • All three write the raw value like updateRows: the editable setting is not checked and no editing event (editCommitted) is emitted.
  • One call is one undo step and one rowsChanged. When the values are already equal nothing happens and the result is false or 0.
  • validate: true on setCellValue runs the column's validation and date rules first. On failure nothing is written, validationFailed is emitted and the result is false.
  • fillColumn defaults to every data row, including rows hidden by a filter. scope: 'visible' limits it to the visible data lines; keys writes only those keys and ignores scope. It returns the number of changed rows.
  • An unknown column id or a calculated column (getValue) throws invalid-option and nothing is written. Unknown row keys are skipped. Group and summary lines are never targets.
  • With saveMode: 'batch' the changed cells appear as modified in the change log.

Apply several changes at once ​

Use transact to remove, update and add in one step.

ts
api.transact({
  remove: [3],
  update: [{ id: 2, name: 'Emma Wilson', department: 'Product' }],
  add: [{ id: 6, name: 'Ethan Hayes', department: 'Engineering' }],
});

The order is remove, update, add. If any step fails, everything is rolled back and an error is thrown, so you never end up with a partial change. rowsChanged fires once, with reason 'transaction'.

Get the API from a wrapper ​

tsx
import { useRef } from 'react';
import { Grid, type GridHandle } from '@maxgrid/react';

const ref = useRef<GridHandle<Employee>>(null);
// ...
<Grid ref={ref} options={options} />;
// ref.current?.addRows([...])

Keep the view when data changes ​

Since 1.3.4

The second argument of setRows and the resort option of addRows and updateRows are available from 1.3.4. Without them everything behaves as before.

setRows(rows, { scroll, keep }) decides what stays when you load new data.

ts
api.setRows(fresh); // as today: scroll, sort, filter, page and expansion stay; selection and focus stay for surviving keys
api.setRows(fresh, { scroll: 'top' }); // only the vertical scroll goes to the top (horizontal stays)
api.setRows(fresh, { keep: ['selection', 'sort'] }); // keep only these, reset the rest
keep itemKeptLeft out
selectionOnly keys that exist in the new data stay selectedSelection is cleared
focusThe focus cell stays if its key existsFocus is cleared
sort, filterThe model staysSort and filter are cleared
pageThe page number stays, clamped to the last pageBack to page 1
expansionExpansion of surviving group and tree keys staysBack to the default depth
  • Without keep everything stays (today's behavior). With an array, only the items you leave out are reset, and the reset happens before the rows are replaced.
  • scroll: 'keep' (default) leaves the position as it is and clamps it to the new height. If the row of an open editor disappears the edit is cancelled.
  • Unknown names or values are an invalid-option before anything changes.

To stop rows from jumping while a sort is active, pass resort: false.

ts
api.addRows([row], { resort: false }); // appended after the sorted rows
api.addRows([row], { index: 0, resort: false }); // you can still set the position in data order
api.updateRows([row], { resort: false }); // stays at its current place even if its value changed
  • The temporary place is dropped by the next sort or filter change, setRows or a page change, and the normal sort order returns.
  • Writing the same row again without resort (the default) releases it from its temporary place, and it moves to its sorted position at once.
  • Filters still apply. A row that newly passes the filter is appended at the end.
  • Without a sort nothing differs. The plain number form such as addRows(rows, 3) still works.

Flash changed cells and batch updates ​

Since 1.3.4

changeFlash, the column option flashOnChange, flashCells, transactBatched and flushTransactions are available from 1.3.4. Without them everything behaves as before.

On screens where values change often, such as live prices, you can flash the changed cells briefly.

ts
createGrid(el, {
  columns: [
    { id: 'price', kind: 'number', flashOnChange: true }, // true: flashes even when changeFlash is off
    { id: 'memo', flashOnChange: false }, // false: never flashes
  ],
  rows,
  changeFlash: { duration: 1000, fade: 500, afterFilter: false }, // true alone uses these defaults
  transactionWaitMs: 50, // how long transactBatched collects (default 50 ms)
});

api.flashCells([{ rowKey: 7, columnId: 'price' }], { duration: 400, fade: 200 }); // flash by hand
api.transactBatched({ update: [tick1] }); // collect and apply together
api.transactBatched({ update: [tick2] }, { waitMs: 0 }); // 0 means the next microtask
api.flushTransactions(); // apply now (nothing happens if nothing is queued)
OptionMeaning
changeFlash.durationHow long the highlight stays fully visible: 100-5000 ms, default 1000
changeFlash.fadeThen how long it fades out: 0-2000 ms, default 500
changeFlash.afterFilterWith true, cells of rows that a filter removed from view also start flashing (they show the remaining time if you clear the filter). Default false
flashOnChangeTurn one column on (true) or off (false). Without it the column follows changeFlash
  • When it flashes: when code changes values (updateRows, transact, transactBatched, setCellValue, fillColumn, updateCells) and when mergeRows merges server values. Cells the user edits in the editor or pastes do not flash. An unchanged value does not flash.
  • Up to 500 cells per frame: if many cells change at once only 500 flash and the rest are skipped silently.
  • The flash is a class: the cell gets mxg-flash and the color is set with --mxg-bg-flash. With prefers-reduced-motion there is no fade animation: it switches on and then off right after the duration. In forced-colors mode an outline is used instead of the background.
  • Batching: changes given to transactBatched are merged in order and applied together. Updating a row that was added in the same batch changes the added value; adding and then removing it cancels out. After the apply one rowsChanged and one transactionsFlushed { transactions, added, updated, removed } are emitted. These changes are not in the undo history. If the merged change fails (for example a duplicate key) an error event (invalid-option) is emitted and the batch is dropped.
  • destroy() clears the timers and the queued changes.

How option updates work ​

setOptions(partial) ignores every property whose reference equals the current value. If nothing changed, no event fires. That is why a wrapper can pass the same options on every render without trouble. If validation fails, the call throws and the existing state stays as it was. Events arrive in this order: optionsChanged, rowsChanged (when rows changed), columnsChanged.

Keeping the top rows in place ​

Rows that must always be visible, such as totals or reference values, can be pinned to the top with pinnedRows. They stay right under the header while the rest scrolls.

ts
createGrid(el, { columns, rows, pinnedRows: 3 });
// Keep the pinned rows even when a filter hides them
createGrid(el, { columns, rows, pinnedRows: { count: 3, filter: false } });
ValueMeaning
a numberPins the first N rows. Sorting leaves them on top in their original order. Filters apply as usual
countHow many rows to pin. 0 turns it off
sort: trueThe pinned rows take part in sorting
filter: falsePinned rows stay even when a filter would hide them

Pinning by row key, the bottom zone and external rows outside the data are in Pin rows to the top or bottom.

With pagination, tree or grouping, pinnedRows is ignored. Change it at runtime with setOptions({ pinnedRows }).

Empty data and loading ​

An empty rows array shows the empty-data message, and loading: true shows the loading message. Change the text with locale ('ko' | 'en') and messages (noRows, loading).

Change the overlays: skeleton, your own drawing, forcing ​

The overlays option decides how the notices look. Without it only the messages above appear.

ts
overlays: {
  loading: 'skeleton',                 // placeholder rows while loading
  skeletonRows: 6,                     // 1-30, default 8
  noRows: 'Nothing here yet.',
  noMatch: (host) => { host.textContent = 'Nothing matches the filter.'; },
}
KeyValueEffect
loadingtext, 'skeleton', functionWhile loading (loading: true); 'skeleton' is only valid here
noRowstext, functionWhen there are no visible rows
noMatchtext, functionRows exist but the filter hides all of them; falls back to noRows
skeletonRowsinteger 1-30Number of skeleton rows, default 8
  • A function draws into the host element. If it returns a cleanup function, that is called once when the notice changes, disappears or the grid is destroyed. If the function throws, the error is reported through the error event (callback-error) and the default message is shown.
  • overlays: false shows no notice at all (showOverlay too).
  • Skeleton rows are decoration. They are not rows, so selection, focus, export and row counts never see them. The motion stops under prefers-reduced-motion and in forced-colors mode.
  • api.showOverlay('loading' | 'noRows' | 'noMatch' | text | function) covers the visible body with that notice regardless of the row count until api.hideOverlay(). hideOverlay() returns to the automatic behavior.
  • The notice has role="status", and the grid root gets aria-busy="true" while the loading notice is shown.
  • A loading cell per column (loadingRenderer) and placeholder rows from a server come with server rows in 1.3.8.

Deciding what is the same value (valueEquals) ​

updateRows neither writes nor notifies when it only gets new objects with equal values, and change tracking drops a cell that came back to its original value. The default test is a deep comparison (deepEqual). To compare object values differently, give the column valueEquals: (a, b) => boolean (for example, same id means same value). Only updateRows calls that pass whole rows get the no-change check from this test; a row with only some properties is always treated as an update, as before. If it throws or returns a non-boolean, the error is reported through the error event (callback-error) and the deep comparison is used. For a column with valueEquals, that test decides; the other properties of the row are compared deeply.

Look up values and lines ​

These are read-only. Unknown keys or columns do not throw; you get undefined, null, '' or []. An exception in a user callback (getValue, formatValue, the function of findRows) is reported as an error event (callback-error) and a fallback value is returned.

MethodReturns
getCellValue(rowKey, columnId)The value the column reads. undefined if the row is missing
getCellText(rowKey, columnId)The text as displayed (formatValue applied). It is computed from the column definition, so rows that are not rendered work too. '' if missing
getColumnValues(columnId, { visibleOnly })The column's values in data order. With visibleOnly, only rows passing the filter
getDistinctValues(columnId, { visibleOnly, sort })Distinct values, first-seen order by default, or 'asc' / 'desc'. Blank values are left out. The kind of value matters and the same date counts once
findRows(match)The matching rows in data order. An object matches rows where every listed column is ===; a function is (row, key) => boolean
getKeyAtVisibleIndex(i)The row key of visible line i. undefined for group and summary lines and out of range
getDisplayRowKind(i)'data', 'group', 'summary'; undefined out of range
getFilteredRowCount()Data rows passing the filter, across all pages, without group and summary lines
getCurrentPageRows()The data rows of the current page (all visible rows without paging)
getFocusedCell()The focused cell { rowKey, columnId }, or null
getSummaryText(columnId)The text of that column in the bottom grand-total line (aggregateFormat applied). null without a summary. With several lines, the topmost
getPinnedRowCount(), isPinning()The number of pinned rows, and whether there is any pinned column or row

getVisibleRowCount() counts screen lines including group and summary lines, while getFilteredRowCount() counts data rows only. They can differ.

Methods tied to the rendered grid are added by the renderer.

MethodReturns
getGridElement()The grid root element
getCellElement(rowKey, columnId)The cell element, or null when it is not rendered (virtualized) or filtered out
locateCell(event)The body data cell { rowKey, columnId } the event happened in. null for the header, group lines and outside the grid
getTopVisibleIndex()The line number at the top of the body
getVisibleRange(){ first, last } of the rendered lines (pinned rows excluded). -1, -1 if none
ts
api.getGridElement().addEventListener('click', (event) => {
  const cell = api.locateCell(event);
  if (cell) console.log(api.getCellText(cell.rowKey, cell.columnId));
});

Try them in the gallery examples Read cell values and lists from code and Find the clicked cell and the rendered line range.

Size rows to their content ​

With rowHeight: 'auto' each row is measured and uses its own content height. Give columns whose text wraps wrap: true. The minimum row height is the default (32px).

ts
createGrid(el, {
  rowHeight: 'auto',
  columns: [{ id: 'memo', title: 'Memo', width: 220, wrap: true }],
  rows,
  rowKey: 'id',
});
OptionDescription
rowHeight: 'auto'Only drawn rows are measured, all at once on the next frame. Rows not measured yet are estimated by the average measured height.
ColumnDef.wrapWraps cell text (by word for Korean). Needed for rows to grow under 'auto'.
headerHeight: 'auto'The header grows to fit titles with wrapHeader: true. Minimum is the default 36px.
ColumnDef.wrapHeaderWraps the header title.
headerLayerHeightsHeight in px per header layer, as an array. The length must equal the number of layers (group nesting depth + 1).
summary.rowHeightHeight of summary lines in px. Default is rowHeight.
autoGridHeighttrue or { maxRows }. Sets the grid height to header + rows and scrolls from maxRows rows (default 50).
api.remeasureRows(keys?)Drops measured heights and measures again. All rows when keys are omitted.
  • To let users drag row heights, see Resize rows by dragging.
  • Resizing a column, hiding or showing one, or changing wrap drops the measured heights. A row whose values changed is measured again on its own. Late-arriving fonts trigger one more measurement.
  • When rows above change height, the row you are looking at stays where it is.
  • Pinned rows, full-width rows and detail lines use their own height and are not measured.
  • rowHeight: 'auto' with the server row model, autoPageSize or bodyLayout is invalid-option.
  • Without the options nothing changes. autoGridHeight removes the need for the container to set a height, but with very many rows keep maxRows small.

Row height dragging ​

With rowsResizable on, drag the bottom edge of a row-number cell (touch included) to change a row height, or use setRowHeight, resetRowHeights and getRowHeights. On touch the row-number cell does not take the vertical scroll (scroll from another cell). See Resize rows by dragging.

Reorder rows ​

moveRows moves a few rows to another place. It changes the order the row data is stored in, so it is meant for tables shown in their natural order, without sorting or filtering.

MethodWhat it does
moveRows(keys, target)Moves keys to target. The target is one of { before: key }, { after: key }, { index: n } (0-based position among the top level).
moveRowsBy(keys, delta)Moves the chosen rows as one block up (negative) or down (positive) by delta places. It stops at the ends.
indentRows(keys), outdentRows(keys)Tree only. Indenting makes a row the last child of its previous sibling; outdenting makes it the next sibling of its parent. Rows without a previous sibling and top-level rows are skipped.
  • The chosen rows keep their document order. Choose a row together with its descendants and they move together.
  • An unknown key, a pinned row, or a move into the row itself or its descendants fails with invalid-option. The state stays as it was.
  • While sorting, filtering or paging is on, or with the server row model, it is refused with "rows cannot be moved while sorting, filtering or paging is on". A grouped view is refused too.
  • If every row is already in place or skipped, nothing happens and no event fires.
  • One undo reverts one call. Bundles without editing do not record it.
ts
grid.moveRows([6], { before: 2 }); // row 6 goes before row 2
grid.moveRowsBy([3, 4], 1); // rows 3 and 4 down by one
grid.on('rowsMoved', (e) => console.log(e.kind, e.keys, e.parentKey, e.index));
Event or hookContent
rowsMovedOnce per call. Carries keys (moved rows), kind ('move', 'indent', 'outdent'), parentKey (new parent of the first row, null for none), index (position among the new siblings) and source ('api'). rowsChanged follows with reason 'move'.
hooks.beforeMoveRows({ keys, target, kind }) => boolean. Return false to cancel.

Drag rows to move them ​

Since 1.4.0

The rowDrag option, the drag handle column (extraColumns: ['handle']), the events rowDragStarted, rowDragCancelled and rowDropped, and the hook beforeRowDrop are available since 1.4.0. In the modular bundles you need the drag bundle.

With rowDrag on, a drag handle column appears at the front and you drag a handle to move rows. Moving inside one grid is the same as moveRows (one undo step, and source in the rowsMoved event is 'drag'), and rows can also be dragged into another grid. It is off by default.

ts
createGrid(el, {
  columns: [{ id: 'name' }],
  selection: 'multiple',
  rowDrag: true, // or { handle, multiple, dropAsChild, group, accept, mode, label, canDrag, canDrop }
  hooks: { beforeRowDrop: ({ keys, targetKey, position, external, rows }) => true },
});
OptionDefaultContent
handletrueDrag by the handle column (false: drag the body 4px)
multipletrueMove selected rows together
dropAsChildfalseIn a tree, the middle third = child
groupnoneThe group name of this grid
accept[]Group names this grid receives
mode'move'Remove received rows from the source / keep ('copy')
labelfirst cell textText shown while dragging
canDragnone(row, key) => boolean
canDropnone({ keys, targetKey, position, external }) => boolean
  • With handle: false there is no handle column and a drag starts by dragging the row body 4px (not on inputs, buttons or links).

  • dropAsChild is for trees only. The top and bottom thirds mean before and after the row. Without tree it is an invalid-option.

  • mode is the receiver's setting. label is a string or ({ keys, rows }) => string; with several rows the default is "N rows".

  • A row for which canDrag returns false cannot be dragged, and at a place where canDrop returns false no line is drawn and nothing drops.

  • Place the handle column with 'handle' in extraColumns (for example ['check', 'handle', 'rowNumber']). Without it the column goes first, and 'handle' without rowDrag is an invalid-option.

  • Drop position: the top half of the row under the pointer means before it, the bottom half after it (thirds with dropAsChild). The line is drawn between rows and a row to drop into gets a dashed outline. Empty space below the rows means the end.

  • Auto-scroll: dragging to the top or bottom edge scrolls. Places outside the visible window are reached by scrolling.

  • When it cannot be dragged: while sorting, filtering, quick filtering, paging or with the server row model, the handles dim (aria-disabled) and "Rows cannot be dragged while sorting, filtering or paging." is the tooltip. Pinned rows can be neither dragged nor dropped onto.

  • Cancel: Esc, losing window focus and a pointer cancel all cancel (reason in rowDragCancelled: 'escape', 'blur', 'invalid-target', 'hook'). Dropping on itself, under its own descendant, on a pinned row or where canDrop refuses is 'invalid-target'.

  • Touch: long-press the handle for 400ms to start.

  • Keyboard: press ← on the first data cell to move focus to the handle of that row. Space picks up, ↑ ↓ choose the place, Space drops. Esc, → and Tab cancel. Screen readers hear it when you pick up and drop.

  • Events: rowDragStarted { keys }, rowDragCancelled { keys, reason }, rowDropped { keys, targetKey, position, external, mode }. The hook beforeRowDrop gets the same values plus rows; false drops nothing (reason: 'hook').

Between two grids ​

Give both grids a group and an accept and they receive each other's rows. There is no wiring code: the grid being dragged sends the DOM event mxg-rowdrag to the element under the pointer and the receiving grid handles it.

ts
createGrid(a, { rowDrag: { group: 'todo', accept: ['done'] } /* ... */ });
createGrid(b, { rowDrag: { group: 'done', accept: ['todo'], mode: 'move' } /* ... */ });
  • The receiver checks accept, canDrop({ external: true }) and beforeRowDrop, then adds the rows with addRows. With mode: 'move' the source grid removes them, and both grids emit rowDropped (the receiver with external: true).
  • If the row keys (rowKey) of the two grids collide, nothing is received, the drag is cancelled with invalid-target, and the receiver emits a diagnostic event (code: 'row-drag-key-collision').

Things that trip people up ​

If you change rows with api.addRows and your wrapper then passes the old rows array again, the grid sees it as a changed value and puts the data back. The framework state is the source of truth.

  • If your framework state owns the rows, update that state and pass the new array.
  • If you change rows through api, do not pass the rows option again.

Mixing the two makes a row you just added seem to vanish.