T
TanStack3y ago
noble-gold

How to set a default sort by using useReactTable?

is there anything I can use to have the initial load sorted a particular way? I checked the docs and could not find anything.
2 Replies
noble-gold
noble-gold3y ago
Table | TanStack Table Docs
useReactTable / createSolidTable / useVueTable / createSvelteTable `tsx
noble-gold
noble-gold3y ago
One codesandbox here with two examples of approaching default sorting. https://codesandbox.io/s/loving-water-l1gnd7?file=/src/main.tsx - First: Using dynamic user interactive sorting, where a user can sort by clicking on appropriate headers. -> Set the sorting function with useState and provide your initialState as the object in useState, shown on line 19. - Second: Just set initialState when not allowing dynamic sorting otherwise. -> Remove the sorting param from the state object on line 88. Uncomment the initialState object. Your default sorting state will now be set on initialisation of the table. Hope this helps.
aniallator8
CodeSandbox
loving-water-l1gnd7 - CodeSandbox
loving-water-l1gnd7 by aniallator8 using @faker-js/faker, @tanstack/react-table, react, react-dom

Did you find this page helpful?