Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

colour one row of antd table based on condition

I'm using antd table in my project. I want to change the color of one row of table if IsDefaultAccount = true where IsDefaultAccount is from back end

The code of the table in the index.js page is :

<Table
                    className="table-layout"
                    columns={this.state.columns}
                    dataSource={filteredData}
                    rowClassName='data-row'
                    bordered={true}
                    size={"small"}
                    onRowDoubleClick={ (record, index, event) => this.handleEditModal(record) }
                    onRowClick={(record, index, event) => this.handleRowClick(record)}
                    loading={this.state.loading}
                    pagination={{ pageSize: 14 }}
                />
like image 633
Jane Fred Avatar asked Dec 12 '25 07:12

Jane Fred


1 Answers

Assuming that each data-item consists of a IsDefaultAccount property:

<Table
  className="table-layout"
  columns={this.state.columns}
  dataSource={filteredData}
  rowClassName={(record) => record.IsDefaultAccount ? 'data-row active-row' : 'data-row' }
  bordered={true}
  size={"small"}
  onRowDoubleClick={ (record, index, event) => this.handleEditModal(record) }
                    onRowClick={(record, index, event) => this.handleRowClick(record)}
  loading={this.state.loading}
  pagination={{ pageSize: 14 }}
/>

Let me know if this works.

like image 143
shet_tayyy Avatar answered Dec 13 '25 22:12

shet_tayyy