Ant Design Vue使用customCell实现单元格样式根据变量变化而变化
- 需求
根据行数据的级别字段改变指定单元格文字颜色 - 代码
在表格列属性中增加customCell
columns: [
{
title: '序号',
dataIndex: '',
key:'rowIndex',
width:60,
align:"center",
customRender:function (t,r,index) {
return parseInt(index)+1;
}
},
{
title:'评估级别',
align:"center",
dataIndex: 'assessLevel_dictText',
customCell: this.getCustomCellColour//添加此方法
},
{
title:'疾病类型',
align:"center",
dataIndex: 'diseaseType_dictText'
},
{
title:'标准描述',
align:"center",
dataIndex: 'standardDescription',
customCell: this.getCustomCellColour//添加此方法
},
]
在method
中添加方法
getCustomCellColour(record){
switch (record.assessLevel){
case '1':
return {style: {'color': '#9e0418'}};
break;
case '2':
return {style: {'color': '#ec0227'}};
break;
case '3':
return {style: {'color': '#f6ad46'}};
break;
case '4':
return {style: {'color': '#f1cc9c'}};
break;
}
}
- 效果如下