Selection row in shadcn data table
Answered
Frieren posted this in #help-forum
FrierenOP
Hello, I just tried using a data table, I want to export its data to Excel. But before that, how do we get the value for each selected row?
code: https://github.com/herukhoeruman/sdm-fe2/blob/master/app/(dashboard)/generator/_components/data-table.tsx
code: https://github.com/herukhoeruman/sdm-fe2/blob/master/app/(dashboard)/generator/_components/data-table.tsx
Answered by Blue orchard bee
Hello! You can use
More: https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel
getSelectedRowModel to extract the currently selected rows in the table. It returns an array of RowModels from which you can easily extract the data from.More: https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel
3 Replies
Blue orchard bee
Hello! You can use
More: https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel
getSelectedRowModel to extract the currently selected rows in the table. It returns an array of RowModels from which you can easily extract the data from.More: https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel
Answer
Blue orchard bee
Just by doing
You should be able to check for changes when you select a row.
useEffect(() => {
console.log(table.getSelectedRowModel())
}, [table.getSelectedRowModel()])You should be able to check for changes when you select a row.
@Blue orchard bee Hello! You can use `getSelectedRowModel` to extract the currently selected rows in the table. It returns an array of RowModels from which you can easily extract the data from.
More: https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel
FrierenOP
oh I see, thanks guys