TanStackT
TanStack10mo ago
24 replies
standard-azure

Working with Row Selection State

So I have a hard time managing the Row Selection State manually:

onRowSelectionChange: (selection) => {
    const selectedRows = selection();
    const allRows = table.getRowModel().rows;

    console.log(selectedRows, allRows);

    // this will tell the table about the new selection
    return selection
}

selectedRows is really weird. When something is selected, it'll contain the row index and true, like { 1: true }. But every time something is deselected it will just be {}. I cannot rely on table.getSelectedRowModel().rows because it will only contain the selection at the time before updating the state. So it's always one behind.

I need to get the selected rows and write them to context variable, so that it will always contain the currently selected selected rows, but it seems kinda impossible
Was this page helpful?