常用业务:1025 antd表格改变单元格样式

改变单元格样式的属性是作用在columns上的,所以先在columns列上定义方法,如下图:

 columns: [
        {
    
    
          title: 'author_id',
          dataIndex: 'author_id',
          key: 'author_id',
          scopedSlots: {
    
     customRender: 'author_id' },
          customCell: this.onCustomCell,
        },
         ]

定义好后就可以根据自己的判断条件来改变想要改变的单元格样式了

// 单元格属性
    onCustomCell(record, rowIndex) {
    
    
      console.log('record', record, 'rowIndex', rowIndex);
      if (record.tab === 'share') {
    
    
        return {
    
    
          style: {
    
    
            'background-color': 'rgb(255,150,150)',
          },
        };
      }
    },

在这里插入图片描述
如图我是根据tab字段来渲染的第一列,当tab字段全等于share时,给第一列加上背景颜色

Guess you like

Origin blog.csdn.net/qq_45989814/article/details/120962741