Access specific fields in selected rows

1 Answer 51 Views
Grid
Charlie
Top achievements
Rank 1
Iron
Charlie asked on 14 Jan 2022, 10:58 PM | edited on 15 Jan 2022, 12:10 AM

My grid is populated from state after an API call. The piece of state is called data.

const [data, setData] = useState([])
Selection is enabled on the grid, so I can create an array of selected rows with:
let allSelected = data.filter((item) => item.selected)

Objects in allSelected have the shape: 

[{
  _id: 1234
  selected: true,
  name: "Joe",
},
{
  _id: 1235
  selected: true,
  name: "Jim",
}]

After I perform an operation update on the selected rows, what's the best way to hide those rows?

  • Is there a method to get the _IDs of the selected rows?
  • Is there a method to hide a given row by _ID?

I'm looking for some way to filter selected rows from data then update state. Something akin to:

      const filtered = data.filter((item) => !allSelected.includes(item._id))
      setData(filtered)


Thanks!

 

1 Answer, 1 is accepted

Sort by
0
Charlie
Top achievements
Rank 1
Iron
answered on 15 Jan 2022, 05:47 AM

I found a working solution that was fairly simple.

// Filter out the selected rows.
const filtered = rows.filter((item) => !item.selected)
setData(filtered)

Tags
Grid
Asked by
Charlie
Top achievements
Rank 1
Iron
Answers by
Charlie
Top achievements
Rank 1
Iron
Share this question
or