当前,我正在显示表格,其中Protected
列中的单元格在 True 时突出显示为绿色,如果为 False 则突出显示为红色:
Name | Source | Protected
________________________________
Ryan Computer False
Briana Phone, Computer True
Shawn Phone True
Serge Phone False
我的相应代码如下所示:
const columns = [
{
Header: "Name",
accessor: "Name",
style: {
textAlign: "center",
},
},
{
Header: "Source",
accessor: "Source",
style: {
textAlign: "center",
},
},
{
Header: "Protected",
id: "Protected",
accessor: (d) => d.protected.toString(),
getProps: (state, rowInfo) => {
if (rowInfo && rowInfo.row) {
return {
style: {
textAlign: "center",
background: rowInfo.row.protected === "false" ? "red" : "green",
},
};
} else {
return {};
}
},
},
];
是否可以根据相应属性是真还是假来删除Protected
列并用红色或绿色突出显示该列?IESource
Protected
Name | Source (highlighted color)
_____________________________________
Ryan Computer (red)
Briana Phone, Computer (green)
Shawn Phone (green)
Serge Phone (red)
我的数据如下所示:
[
{
"Name": "Ryan",
"Protected": false,
"Source": ["Computer"],
},
{
"Name": "Briana",
"Protected": true,
"Source": ["Phone, Computer"],
},
{
"Name": "Shawn",
"Protected": true,
"Source": ["Phone"],
},
{
"Name": "Serge",
"Protected": false,
"Source": ["Phone"],
}
]