react-table-library icon indicating copy to clipboard operation
react-table-library copied to clipboard

Pre-Selected Rows?

Open evanVerinomics opened this issue 1 year ago • 1 comments

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!

evanVerinomics avatar Apr 06 '24 22:04 evanVerinomics

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 }}>

proddy avatar Apr 07 '24 07:04 proddy