Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-Selected Rows? #150

Open
evanVerinomics opened this issue Apr 6, 2024 · 1 comment
Open

Pre-Selected Rows? #150

evanVerinomics opened this issue Apr 6, 2024 · 1 comment

Comments

@evanVerinomics
Copy link

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!

@proddy
Copy link
Contributor

proddy commented Apr 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants