Skip to content

Component API ​

The Vue and the React component share the same core: columns, options and the grid API are identical. They differ in how state is bound and how content is customized (slots vs. render props). Use the framework switch in the navigation bar to show the API of your framework.

vue
<Datagrid
  :columns="columns"
  :rows="rows"
  :options="options"
  v-model:selectedItems="selected"
  @cell-value-changed="save"
/>

Datagrid is a generic component: the row type is inferred from rows and used for columns, options and the event payloads.

tsx
<Datagrid
  columns={columns}
  rows={rows}
  options={options}
  selectedItems={selected}
  onSelectedItemsChange={setSelected}
  onCellValueChanged={save}
/>

Datagrid is generic: the row type is inferred from rows and used for columns, options, the callbacks and the render props.

Props ​

PropTypeDescription
columnsColumnConfig<T>[]column definitions (required), see column options
rowsT[] | undefineddata; undefined shows the loading indicator
optionsGridOptions<T>see grid options
pinnedTopRowsT[]rows pinned below the header
pinnedBottomRowsT[]rows pinned to the bottom
theme"light" | "dark" | "auto"color theme
eventsPartial<CoreDelegate>low level callbacks of the core
className, styleReact only: class and style of the root element (Vue: class / style attributes)

All props are reactive. options and columns are watched deeply, rows shallowly.

All props can change at any time. columns and options are compared by value (functions by their source), so inline objects don't reset the grid – but memoizing them with useMemo or defining them outside of the component saves work.

Binding state ​

ModelTypeDescription
v-model:rowsT[]updated after editing and pasting
v-model:selectedItemsItemUid[]ids of the selected rows
v-model:selectedCells{ item: ItemUid; column: string }[]selected cells
v-model:expandedItemsItemUid[]expanded tree and group rows
v-model:sortedColumns{ column: string; asc: boolean }[]sort model
v-model:columnFilter{ column: string; value: unknown }[]column filters, see filter values
v-model:globalFilterunknownquick filter
v-model:columnGroupsstring[]ids of the grouped columns
v-model:pageIndexnumbercurrent page (zero based)

Each piece of state can optionally be controlled: pass the value and its change callback. Without the value the grid manages the state itself (uncontrolled); the callback alone can be used to observe changes.

Value propChange callbackType
rowsonRowsChangeT[] – called with a new array after editing and pasting
selectedItemsonSelectedItemsChangeItemUid[]
selectedCellsonSelectedCellsChange{ item: ItemUid; column: string }[]
expandedItemsonExpandedItemsChangeItemUid[]
sortedColumnsonSortedColumnsChange{ column: string; asc: boolean }[]
columnFilteronColumnFilterChange{ column: string; value: unknown }[], see filter values
globalFilteronGlobalFilterChangeunknown
columnGroupsonColumnGroupsChangestring[]
pageIndexonPageIndexChangenumber

Controlled means controlled

A controlled value without a change callback (or with a callback that ignores the value) is re-applied after every user interaction – e.g. columnFilter={[]} without onColumnFilterChange makes the filter row read-only. This is the usual React behavior of controlled inputs.

Events ​

EventPayload
readyapi: Core – the grid is initialized
cell-click{ event, row, column, data, value }
cell-dblclick{ event, row, column, data, value }
cell-contextmenu{ event, row, column, data, value }
header-contextmenu{ event, column }
cell-value-changed{ item, column, data, oldValue, newValue, source }
selection-change{ keys, rows, cells }
sort-change{ column, asc }[]
filter-change{ column, value }[]
group-changestring[]
page-changePaginationState
column-resizeColumn
row-drop{ row, target, position } – see row dragging
state-changeGridState
PropPayload
onReadyapi: Core – the grid is initialized
onCellClick{ event, row, column, data, value }
onCellDoubleClick{ event, row, column, data, value }
onCellContextMenu{ event, row, column, data, value } – call event.preventDefault() to suppress the built-in context menu
onHeaderContextMenu{ event, column }
onCellValueChanged{ item, column, data, oldValue, newValue, source }
onSelectionChange{ keys, rows, cells }
onPageChangePaginationState
onColumnResizeColumn
onRowDrop{ row, target, position } – see row dragging
onStateChangeGridState
eventsPartial<CoreDelegate> – low level callbacks of the core

Customizing content ​

SlotPropsDescription
cell-<columnId> / cellvalue, text, row, data, column, setValue, apicell content
header-<columnId> / headercolumn, text, apiheader content
filter-<columnId> / filtercolumn, value, setValue, apifloating filter
editor-<columnId> / editorvalue, setValue, submit, cancel, row, data, column, apieditor
detailrow, data, apidetail row content
groupgroup, key, text, count, column, apigroup row content
toolbarapiabove the grid
footerapibelow the grid
empty–no rows
loading–loading indicator
overlayapilayer on top of the grid
statusbaritems, info, apicontent of the status bar
PropParametersDescription
cellRenderersRecord<columnId | "*", (params) => ReactNode>, params: value, text, row, data, column, setValue, apicell content
headerRenderersRecord<columnId | "*", (params) => ReactNode>, params: column, text, apiheader content
filterRenderersRecord<columnId | "*", (params) => ReactNode>, params: column, value, setValue, apifloating filter
renderDetail{ row, data, api }detail row content
renderGroup{ group, key, text, count, column, api }group row content
renderStatusBar{ items, info, api }content of the status bar
renderEmpty–no rows
renderLoading–loading indicator
toolbarReactNode | (api) => ReactNodeabove the grid
footerReactNode | (api) => ReactNodebelow the grid
overlayReactNode | (api) => ReactNodelayer on top of the grid

Custom editors are components set with the column option editComponent, see custom editors.

Renderers are called while rendering the grid – keep them cheap and define them outside of the component or with useMemo when they don't depend on state.

Methods ​

Access them with a template ref:

ts
const grid = ref<InstanceType<typeof Datagrid>>();
grid.value?.exportCsv();
grid.value?.core.sortColumn("name", "asc");
MemberDescription
core / apithe complete grid API
exportCsv(params?)download csv
getDataAsCsv(params?)csv text
selectAll(), deselectAll()
expandAll(), collapseAll()
getState(), setState(state)
refresh()re-apply sorting and filters, reload server side data
autosizeColumns(columns?)
focus()move the browser focus into the grid
undo(), redo()undo / redo the last cell change

Access the API with a ref:

tsx
const grid = useRef<DatagridHandle>(null);
grid.current?.exportCsv();
grid.current?.api.sortColumn("name", "asc");

<Datagrid ref={grid} ... />
MemberDescription
apithe complete grid API
exportCsv(params?)download csv
getDataAsCsv(params?)csv text
selectAll(), deselectAll()
expandAll(), collapseAll()
getState(), setState(state)
refresh()re-apply sorting and filters, reload server side data
autosizeColumns(columns?)
focus()move the browser focus into the grid
undo(), redo()undo / redo the last cell change

The API is also passed to onReady.

Headless hook ​

useDatagrid(columns, rows, options) (a composable in Vue, a hook in React) uses the grid logic without the grid UI – see headless usage.

Released under the ISC License.