I have a table where I’d like to highlight specific cells based on the values in a state array. For example, if I have an array like this:
const newUsers = [ { id: 0, user: "Chic Footitt" }, { id: 2, bio: "...." } ];
I want to set the background of a cell in the table to red if:
- The row’s
id
matches anid
in thenewUsers
array. - The column key (e.g.,
user
,bio
) exists in the corresponding object in thenewUsers
array.
I want to check if the column key is present in the array for the matching row and, if so, highlight the cell with a red background.
While attempting to implement this, I tried accessing item
and setting the logic in the table’s background value. However, I’m encountering issues where item
is undefined, and the same happens with currentSourceRow
. Is it possible to achieve this dynamically? My goal is to highlight random cells as long as they meet the criteria in the array, so I’m looking for a dynamic way to handle this.