Table state and editing
Keep sorting, selection, and edits in sync with your app.
Sync sorting with your app
Control sorting when it must stay in sync with a URL, server request, or another view. Pass both the current sort and its change handler. The handler can receive a new value or an updater function. Use initialState when the table should manage subsequent changes.
Outside Ghost's subscribed renderers, use table.Subscribe or TanStack's selector hooks for reactive reads. Adding an engine feature does not add its surrounding controls: compose those in the application.
Reuse a table instance in Data grid
Pass table to DataGrid to retain the same data, accessor and feature configuration. columnDef.meta.dataGrid adds editable, validate, renderEditor, or other grid policies. The grid adapts the instance's current row model and visible/pinned columns; avoid keeping a parallel filtered row list. Instance mode binds supported sorting, sizing, order and visibility methods; supplied callbacks also receive the requests.
For a small grid, pass rows as stable { id, data } records. An edit gives you a string draft even for a numeric column. Parse and validate it before changing the record.
The grid handles focus, selection, and the draft while a cell is open. A custom renderEditor receives the draft and the onChange, commit, and cancel callbacks. Use onEditStateChange to show surrounding feedback.
Treat onCellEdit as a request to update your rows. If saving takes time, show pending and error states in your app. Keep the previous value for rollback and ignore a late response if a newer edit superseded it. Check write permission on the server.
Choose client or server operations
Client operations apply to the rows already loaded. To sort or filter the entire dataset on a server, pass manualSorting or manualFiltering and return the processed rows. Use manualPagination for server paging and supply the row or page count. Include the controlled state in the request key so changing it fetches the correct page.
Abort or ignore superseded requests. Decide whether off-page selections persist and resolve selected IDs against your backend before an operation. Stable IDs do not imply that an off-page row is loaded. Reordering requests are meaningful only when the application allows an ordering independent of the current sort/filter.
When to pass your own instance
The raw rows and columns API reports sort, hide, and reorder requests. Pass your own TanStack instance for filtering, paging, or more feature controls. Use paging or a separate virtualized view to bound the number of rows you render.
See Data grid API, Table API, and TanStack controlled state.