@@ -26,7 +26,10 @@ import { makeData } from './makeData'
2626import type {
2727 CellData ,
2828 Column ,
29+ ColumnFiltersState ,
30+ PaginationState ,
2931 RowData ,
32+ SortingState ,
3033 StockFeatures ,
3134 TableFeatures ,
3235} from '@tanstack/react-table'
@@ -96,6 +99,15 @@ function App() {
9699 const [ data , setData ] = React . useState < Array < Person > > ( ( ) => makeData ( 5_000 ) )
97100 const refreshData = ( ) => setData ( ( _old ) => makeData ( 50_000 ) ) // stress test
98101
102+ const [ sorting , setSorting ] = React . useState < SortingState > ( [ ] )
103+ const [ columnFilters , setColumnFilters ] = React . useState < ColumnFiltersState > (
104+ [ ] ,
105+ )
106+ const [ pagination , setPagination ] = React . useState < PaginationState > ( {
107+ pageIndex : 0 ,
108+ pageSize : 10 ,
109+ } )
110+
99111 // Using useLegacyTable with the v8-style API!
100112 // Notice how we use get*RowModel() options instead of _rowModels
101113 // and we don't need to define _features
@@ -107,15 +119,19 @@ function App() {
107119 getFilteredRowModel : getFilteredRowModel ( ) , // client side filtering
108120 getSortedRowModel : getSortedRowModel ( ) , // client side sorting
109121 getPaginationRowModel : getPaginationRowModel ( ) ,
122+ state : {
123+ columnFilters,
124+ pagination,
125+ sorting,
126+ } ,
127+ onColumnFiltersChange : setColumnFilters ,
128+ onPaginationChange : setPagination ,
129+ onSortingChange : setSorting ,
110130 // Debug options work the same
111131 debugTable : true ,
112132 debugColumns : true ,
113133 } )
114134
115- // With useLegacyTable, we can use the v8-style getState() method
116- // or access state directly from table.state (both work the same)
117- const { columnFilters, pagination, sorting } = table . getState ( )
118-
119135 return (
120136 < div className = "p-2" >
121137 < div className = "mb-4 p-2 bg-yellow-100 border border-yellow-400 rounded" >
0 commit comments