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

I have a situation where I have to change background color of rows depending upon row props. I am curre

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745073698a4609707.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信