How rows render
Body rows are memoized. A row re-renders only when its own data, selection, expansion
or editing state changes. Changes that concern every row re-render all of them: a new
columns array, column visibility, order and sizes, grouping and size changes.
The browser adds its own cost on top of React. A <table> is laid out as a whole, so any
change in one cell makes the browser re-layout all rows that are in the DOM. Virtualized rows
are independent blocks and do not pay this cost. The number of rows in the DOM is what
every interaction costs, keep it small.
Rows in the DOM
- Up to about a thousand rows render fine without extra setup.
- Above that, paginate with
pageSizeor setvirtualize="rows"withheight. Row selection, expansion, editing and grouping work the same way in both modes, see Virtualization for the exceptions. - Grids with 50 or more columns need
virtualize="columns"orvirtualize="rows,columns". - Tree data with thousands of expanded rows needs row virtualization as well, the row count that matters is the number of visible rows.
Stable options
useDataGrid options and DataGrid props are compared by identity. A value created during
render is new on every render, and the grid treats it as a change. Define these values outside
the component or wrap them in useMemo/useCallback:
data– a new array rebuilds the row model and re-renders every row, it also resets the page index, expanded rows and cell selectioncolumns– a new array remounts every cellenableRowSelection,enableMultiRowSelection,getRowCanExpand,getCellStatusandgetRowHeightfunctionslabels,classNames,stylesandattributesobjects
Event handlers such as onRowClick, onEditSave and renderExpandedRow can be inline,
rows always call the latest version without re-rendering.
Cell renderers
A cell function runs every time its row renders. Keep it cheap: create Intl formatters
and lookup tables at module level, and prefer plain text or a Badge over a component with
its own state. A row action menu is fine, its dropdown is not rendered until it opens.
Values that cells read from your own React context must be memoized too. A context value created on every render re-renders every cell that reads it:
Sorting and filtering large data sets
Client-side sorting and filtering go through every row. With a hundred thousand rows, each sort or each search keystroke takes a noticeable fraction of a second, while the grid renders only the rows on screen. Debounce the search input and pass the debounced value to the store, the input itself stays responsive:
Above a few hundred thousand rows, or when the data does not fit in memory, move sorting, filtering and pagination to the API, see Server-side.
Finding the cause of slow renders
Use the React DevTools profiler with "Record why each component rendered" enabled. When every body cell renders after an unrelated state change, one of the options listed in Stable options is created during render. When only a few cells render but the interaction is still slow, the cost is in the browser layout, reduce the number of rows in the DOM.