Ant Design Vue 表格单元格背景颜色动态设置 - 根据字段值改变颜色
可以通过在 customCell 中使用 style 属性来改变单元格的背景颜色。可以根据 record.pdSign 的值来设置不同的背景颜色,例如:
const columns: BasicColumn[] = [{
title: '亏盈标志',
dataIndex: 'pdSign',
fixed: 'left',
customCell: ({ text, record }) => {
let backgroundColor;
if (record.pdSign === '盈') {
backgroundColor = 'green';
} else if (record.pdSign === '亏') {
backgroundColor = 'red';
} else {
backgroundColor = 'white';
}
return {
style: {
backgroundColor: backgroundColor,
},
children: text,
};
},
}];
在上述代码中,通过 customCell 函数来定义单元格的样式。根据 record.pdSign 的值,设置不同的背景颜色,并将样式设置为 style 属性的值。然后将 text 作为 children 返回,保持单元格的内容不变。
原文地址: https://www.cveoy.top/t/topic/qt1L 著作权归作者所有。请勿转载和采集!