Search code examples
reactjsantd

How to color the background of a row in ant's Table component using reactjs


Hello i want to color the background of a row in ant's Table component. So far i have done this: In my component that i have the table is like this:

   <Table
       size='small'
       dataSource={this.state.codesInfo}
       rowClassName={(record, index) => ((record.package_name===null ? styles.backgroundColor : ''))}
       columns={{....}}

In my style.js i have this

 const styles = {
     backgroundColor: #f5b12c,
 }

 export default styles;

I import my file that i have my Table component like this: import styles from './style.js' When i console.log my styles.backgroundColor i can see the color in the log, but the rows are not change colors


Solution

  • I have found a solution to my problem:

    i make a css file

    .even {
        background-color: #d6d6d6;
     }
    

    Imported like this in my file that i have the antd Table: import './style.css'

    and i use it like this:

     <Table
        size='small'
        dataSource={this.state.codesInfo}
        rowClassName={(record, index) => ((record.package_name===null ? 'even' : ''))}
        columns={{....}}