T
TanStack2mo ago
fascinating-indigo

custom row selection state

hey. is there any way to get the whole row data object for the selected row in row selection state? row selection state defaults to index of the row or we can change it to row._id. But i want to get the row selection state just like how AG-Grid returns it, that is, array of objects, where objects correspond to the row data for each selected row.
5 Replies
xenial-black
xenial-black2mo ago
I think you can just map the data to row.original, and have the original object for each row.
fascinating-indigo
fascinating-indigoOP2mo ago
i am mapping the selected row with its data and storing that into redux. This happens inside a useEffect that runs whenever row selection state changes. I take the id of the selected row and find it inside a cache having id as the key and data object as value (for faster search). Then i dispatch this array of row data objects to redux, and use it in the app. are you also referring to this way for mapping the selected row with its data?
xenial-black
xenial-black2mo ago
Well, I thought you were using table.getSelectedRowModel() to get the selected columns. Then you could use table.getSelectedRowModel().flatRows.map((r) => r.original) to get the original objects for each selected element. But I'm not sure if I understood your question, hopefully this helps.
fascinating-indigo
fascinating-indigoOP2mo ago
no i am not using table.getSelectedRowModel() because it only gives selected rows for the current page. I need to persist selected rows across different pages.
xenial-black
xenial-black2mo ago
Oh, if you are doing server side pagination, then yes. It'll only give the data only for the current page. Unless you use React query with infinite loading and still pass all the data to the table so it can keep track of things.

Did you find this page helpful?