title 亏盈标志 dataIndex pdSign fixed left customRender function text record if recordpdCount 0 text = 盈; recordpdSign = text; return text; el
可以通过在 customRender 中设置单元格的 style 属性来实现单元格颜色的设置。
首先,在 customRender 中根据 pdSign 的值设置对应的颜色。例如,当 pdSign 的值为 '盈' 时,设置 color 属性为 'green';当 pdSign 的值为 '亏' 时,设置 color 属性为 'red'。然后,将 style 对象作为返回值的属性之一,将其传递给单元格的 style 属性。
以下是示例代码:
customRender: function ({ text, record }) {
let style = {};
if (record.pdCount > 0) {
text = '盈';
record.pdSign = text;
style.color = 'green';
return {
children: text,
props: {
style: style
}
};
} else if (record.pdCount < 0) {
text = '亏';
record.pdSign = text;
style.color = 'red';
return {
children: text,
props: {
style: style
}
};
} else {
text = '平';
record.pdSign = text;
return text;
}
}
这样,在渲染表格时,当 pdSign 的值为 '盈' 时,单元格文字将显示为绿色;当 pdSign 的值为 '亏' 时,单元格文字将显示为红色
原文地址: https://www.cveoy.top/t/topic/iNH2 著作权归作者所有。请勿转载和采集!