antd 中table的列 如果按需给className?

比如 消息未读就给'red_color',已读就给'blue_color'

columns是

info_columns: [
    {title: '标题',dataIndex: 'info_title'},
    {title: '消息内容',dataIndex: 'info_content'},
    {title: '时间',dataIndex: 'info_time'},
    {
        title: '类型',
        dataIndex: 'info_type', 
        filters: [
            {text: '消息',value: '1',}, 
            {text: '信息',value: '2',}, 
            {text: '短信',value: '3',}, 
            {text: '状态',value: '4',}, 
            {text: '工作',value: '5',}
        ]
    }
]

我想根据info_state(已读1,未读0),给 {title: '标题',dataIndex: 'info_title'},列 加一个className
属性。

总的一句话 antd table 如何 给同一列不同行 添加不同的className?

阅读 8.4k
1 个回答

info_columns: [

{
    title: '标题',
    dataIndex: 'info_title',
    render: (text, record) => <span className={record.info_state == 1? "OK" : 'error'}>{text}</span>
},
{title: '消息内容',dataIndex: 'info_content'},
{title: '时间',dataIndex: 'info_time'},
{
    title: '类型',
    dataIndex: 'info_type', 
    filters: [
        {text: '消息',value: '1',}, 
        {text: '信息',value: '2',}, 
        {text: '短信',value: '3',}, 
        {text: '状态',value: '4',}, 
        {text: '工作',value: '5',}
    ]
}

]

这个三目运算的判断根据你的info_state的数据类型来判断

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