antd中的table,如何根据单元格数据不同显示不同的背景色

求大佬详细解释,看过其他人的回答,还是不太清楚怎么设置的样式

阅读 12.1k
3 个回答

用css就可以了

.ant-table-tbody tr:nth-child(2n) {
    background-color: grey;
}

单元格可以用jsx:

{
  title: '编号',
  dataIndex: 'orderNo',
  align: 'center',
  render: val => <span className="red-style">{val}</span>,
}

或者onCell:

{
  title: '编号',
  dataIndex: 'orderNo',
  onCell: (record, rowIndex) => ({
    style: {
      backgroundColor: 'red'
    }
  })
}

这个在cloumn里可以设置的,通过返回render方式来自定义单元格的样式

新手上路,请多包涵

render: (text, record) => {
if(record.条件===条件值){

return (
  text > 25000 ?
    (
      <span style={{ color: 'red' }}>{text}</span>
    ) : (  text <= 0 ?
    (
      <span style={{ color: 'yellow' }}>{text}</span>
    ) : <span>{text}</span>)
);

}

其他条件在加if写下去就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题