Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
I want to change the background colour of columns of ant design table if the index of my data is even

I want to change the background colour of columns of ant design table if the index of my data is even any idea how to change the background of columns on this condition.i have data in list want to set a condition through loop any idea how to change the background of columns in ant design.

 const [dataSource, setDataSource] = useState([])
 const { list } = useSelector((state) => state.userData) 
  useEffect(() => {

    dispatch(getData(token))
    setDataSource(list)
    dispatch(getDataofFormularyDrug(0))

   }, [])

      <Table
    columns={columns}
    // dataSource={list}
    dataSource={dataSource}
    pagination={{
      pageSize: 10
    }}
  />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do this using the CSS pseudo-class :nth-child() with the keyword even to change the background color for each table cell. In your CSS File you can add the following line bellow:

.ant-table-tbody .ant-table-cell:nth-child(even) {
  background-color: #fafafa;
}

I created a complete example at CodePen with the basic table from Ant Design changing the background color for the table cell when it is even. Follow the link: https://codepen.io/marcelofreires/pen/eYyZqer.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!