Replies: 2 comments
-
I resolved it by using controlled state, and initialising my state with initial columns selected. const MyTable = ({data}) => {
const intialSelections = useMemo(() => data
.map((dataItem) => dataItem.isSelected)
.reduce((acc, b) => {
acc[b] = true
return acc;
}, {}), []);
const [selectedLines, setSelectedLines] = useState(intialSelections);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
enableRowSelection: true,
onRowSelectionChange: setSelectedLines,
state: {
rowSelection: selectedLines,
}
});
// return <TableComponent columns />
} note: MyTable component only loads when data is present, else I show a loading component. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The original question seemed to be using the wrong data type. Use the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My mind is almost expoilt, can´t make a initial state of rows selection with table react table. Try to put initial state by "rowSelection", works fine when i put a string like this: [true, false, true, false]. But when i'm trying to get asyncronily this data it doesn´t work, and first value taken when render is a enmpy string for "initialSelectedRowIds()", because el estado "data" is too a empy string at first render. How can i make it corretly??, please help me.
One more thing, the data is rendering fine in table. I whondering why "data" is empy when i'm trying put initial rows selected. I tried to use useMemo for put initial rows selected, it didn't work too.
Beta Was this translation helpful? Give feedback.
All reactions