Pre-Selected Rows?
I'm trying to figure out how to keep rows selected in a table even after the data refreshes every 10 minutes. Here’s what I’ve got so far:
function onSelectChange(action, state) { console.log('state: ', state); console.log('selectedRowIds: ', selectedRowIds); let { ids: selectedIds } = state; // let selectedIds = selectedRowIds; // tried this, doesn't work! console.log("selected ids: ", selectedIds); console.log("type: ", action.type); ... }
I have an array called selectedRowIds with IDs like [1, 3, 6], but I'm stuck on how to use it to initialize selected rows when the data reloads. Right now, whenever the app pulls new data (which is every 10 minutes), all the previously selected rows lose their checked status.
Does anyone have any tips on how to maintain the selection status through data refreshes? Thanks for any help you can offer!
not sure if it helps, for single selection I grab the state.id and store it
async function onSelectChange(action: any, state: any) {
setSelectedDevice(state.id);
if (action.type === 'ADD_BY_ID_EXCLUSIVELY') {
await readDeviceData(state.id);
}
}
const device_select = useRowSelect(
{ nodes: coreData.devices },
{
onChange: onSelectChange
}
);
...
<Table data={{ nodes: coreData.devices }} select={device_select} theme={device_theme} layout={{ custom: true }}>