最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react-table: change background color of rows depending upon row props value - Stack Overflow

programmeradmin1浏览0评论

I have a situation where I have to change background color of rows depending upon row props. I am currently doing this:

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

In react-table, it is like this:

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

If I inspect the element, I do get this:

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

but it doesn't apply on the row. How can I resolve this?

My react version is ^16.13.1 and react-table version is 6.8.6.

I have a situation where I have to change background color of rows depending upon row props. I am currently doing this:

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

In react-table, it is like this:

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

If I inspect the element, I do get this:

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

but it doesn't apply on the row. How can I resolve this?

My react version is ^16.13.1 and react-table version is 6.8.6.

Share asked Oct 16, 2020 at 11:06 SaaniSaani 78210 gold badges29 silver badges75 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 0

First, you are wrong with assigning style. you might want to pass background-color as object style.

e.g.

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

Also instead of passing empty string as default, you might want to pass 'white' or color you want as default.

I think that is the most reason, please let me know if it doesn't work.

Example link which is written by react-table maintainer https://codesandbox.io/s/k3q43jpl47

发布评论

评论列表(0)

  1. 暂无评论