react-table preselected rows by actual object data field

  javascript, react-table

I’m currently using this example to create a table with selectable checkboxes.

https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/row-selection?from-embed=&file=/src/App.js:3058-3085

I’m currently running into an issue where I need to prefill the table with specific object ids.

For example, I have a selectedPeopleIds = ["1", "5"] and I want the selectedRowIds to select object with the ids of 1 and 5 only.

{
  "firstName": "care",
  "lastName": "pizzas",
  "age": 22,
  "visits": 86,
  "progress": 60,
  "status": "single",
  "subRows": [
    {
      "firstName": "engineering",
      "lastName": "observation",
      "age": 20,
      "visits": 72,
      "progress": 83,
      "status": "complicated",
      "ID":1
    },
    ....
      "firstName": "engineering",
      "lastName": "observation",
      "age": 20,
      "visits": 72,
      "progress": 83,
      "status": "complicated",
      "ID": 5
    },
 }

}

However, I noticed that selectedRowIds is different from selectedFlatRows[].original where the selectedRowId just represents the index on the table, while the selectedFlatRows.[].original holds the data of the people I want to select.

Is there a way to map the selectedFlatRows to selectRowIds so that I know which indexes I need to prefill?

Source: Ask Javascript Questions

LEAVE A COMMENT