Ant Design Vue使用customCell实现单元格样式根据变量变化而变化

Ant Design Vue使用customCell实现单元格样式根据变量变化而变化

  1. 需求
    根据行数据的级别字段改变指定单元格文字颜色
  2. 代码
    在表格列属性中增加 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;
          }
      }
  1. 效果如下
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值