Sorting and Filtering the Data Yourself
By default, the
<DataSource /> sorts and filters the data in the browser - for array data, for a Promise, for a data function, and also when sortInfo or filterValue are controlled.When you sort or filter the data yourself - on a server, in a data-fetching library like TanStack Query, or in your own code - tell the
<DataSource /> not to do it again, with shouldReloadData:- with a
datafunction, it's called again on every sort or filter change, with thesortInfoandfilterValuein its params; - with array data, you pass a new array every time the sorting or the filtering changes (eg from
onSortInfoChangeandonFilterValueChange).
Either way, the rows are shown as they come in - they are not sorted or filtered again in the browser.
Grouping and pivoting are always done in the browser - unless you use
lazyLoad, where the server returns the groups.Reusing the built-in sorting and filtering#
To sort and filter the data the same way the
<DataSource /> does, use the functions it uses:multisort(sortInfo, array)- the built-in sorting for flat data (it sorts the array in place, so pass a copy);defaultFilterFunction(param)- the built-in column filtering for one row. It needs the row, its index, the array, the primary key, and the column filters with their filter types - the defaultfilterTypesare exported too.
If you configure custom
filterTypes on the <DataSource />, pass the same ones to defaultFilterFunction.With TanStack Query#
The query key includes the sorting and the filtering, so every change runs a new query. Thanks to
placeholderData: keepPreviousData, the previous rows stay on screen until the new ones arrive - and because the <DataSource /> doesn't sort or filter them itself, they don't change until the query resolves.#
Sorting and filtering with TanStack Query
loading demo…