0

我有一种情况,我必须根据行道具更改行的背景颜色。我目前正在这样做:

const getTrProps = (state, rowInfo, instance) => {
        if (rowInfo) {
            return {
                style: {
                    'background-color': rowInfo.original.customercomplaints.order_ref === currentOrderId ? '' : 'yellow',
                }
            }
        }
        return {};
    }

react-table,是这样的:

<ReactTableFixedColumns className="-striped"
      columns={customerComplaintsColumns}
      data={customerComplaintsData}
      daultPageSize={10}
      defaultFilterMethod={filterCaseInsensitive}
      getTrProps={getTrProps}
      />

如果我检查元素,我会得到:

<div class="rt-tr -even" role="row" style="background-color: yellow;">

但它不适用于行。我该如何解决这个问题?

我的react版本是^16.13.1react-table版本是6.8.6

4

1 回答 1

0

首先,您在分配样式方面是错误的。您可能希望将背景颜色作为对象样式传递。

例如

        return {
            style: {
                'background': rowInfo.original.customercomplaints.order_ref === currentOrderId ? '' : 'yellow',
            }
        }

此外,您可能希望将“白色”或您想要的颜色作为默认值传递,而不是将空字符串作为默认值传递。

我认为这是最重要的原因,如果它不起作用,请告诉我。

由 react-table 维护者编写的示例链接 https://codesandbox.io/s/k3q43jpl47

于 2020-10-16T11:35:58.760 回答