MCPcopy Index your code
hub / github.com/TanStack/table / App

Function App

examples/react/sorting/src/main.tsx:25–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25function App() {
26 const rerender = React.useReducer(() => ({}), {})[1]
27
28 const [sorting, setSorting] = React.useState<SortingState>([])
29
30 const columns = React.useMemo<ColumnDef<Person>[]>(
31 () => [
32 {
33 accessorKey: 'firstName',
34 cell: info => info.getValue(),
35 //this column will sort in ascending order by default since it is a string column
36 },
37 {
38 accessorFn: row => row.lastName,
39 id: 'lastName',
40 cell: info => info.getValue(),
41 header: () => <span>Last Name</span>,
42 sortUndefined: 'last', //force undefined values to the end
43 sortDescFirst: false, //first sort order will be ascending (nullable values can mess up auto detection of sort order)
44 },
45 {
46 accessorKey: 'age',
47 header: () => 'Age',
48 //this column will sort in descending order by default since it is a number column
49 },
50 {
51 accessorKey: 'visits',
52 header: () => <span>Visits</span>,
53 sortUndefined: 'last', //force undefined values to the end
54 },
55 {
56 accessorKey: 'status',
57 header: 'Status',
58 sortingFn: sortStatusFn, //use our custom sorting function for this enum column
59 },
60 {
61 accessorKey: 'progress',
62 header: 'Profile Progress',
63 // enableSorting: false, //disable sorting for this column
64 },
65 {
66 accessorKey: 'rank',
67 header: 'Rank',
68 invertSorting: true, //invert the sorting order (golf score-like where smaller is better)
69 },
70 {
71 accessorKey: 'createdAt',
72 header: 'Created At',
73 // sortingFn: 'datetime' //make sure table knows this is a datetime column (usually can detect if no null values)
74 },
75 ],
76 []
77 )
78
79 const [data, setData] = React.useState(() => makeData(1_000))
80 const refreshData = () => setData(() => makeData(100_000)) //stress test with 100k rows
81
82 const table = useReactTable({

Callers

nothing calls this directly

Calls 8

makeDataFunction · 0.90
useReactTableFunction · 0.90
flexRenderFunction · 0.90
getCoreRowModelFunction · 0.85
getSortedRowModelFunction · 0.85
getContextMethod · 0.80
refreshDataFunction · 0.70
rerenderFunction · 0.50

Tested by

no test coverage detected