【问题标题】:react-table: change background color of rows depending upon row props valuereact-table:根据行道具值更改行的背景颜色
【发布时间】:2021-01-30 21:41:42
【问题描述】:

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

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

【问题讨论】:

    标签: javascript reactjs react-table react-table-v6


    【解决方案1】:

    首先,您在分配样式时出错了。您可能希望将背景颜色作为对象样式传递。

    例如

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

    除了默认传递空字符串之外,您可能还想传递“白色”或您想要的默认颜色。

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 2014-09-30
    • 2016-05-15
    • 1970-01-01
    相关资源
    最近更新 更多