element - table 单元格自定义颜色设置

table 单元格自定义颜色设置

通过下方的方法 通过 表头 设置对应 列的单元格(颜色/其他数据)

注意点:单元格数据是需要,确定是那一列,哪一个单元格的
核心代码

if (i == column.property) {
  return cellStyle
}
  1. cell-style 单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的
   cellStyle({row, column, rowIndex, columnIndex}) {
      let cellStyle;
      for (let i = 0; i <= 2; i++) {
        switch (row[i]) {
          case "1":
            cellStyle = 'background: #FFFF80';
            break
          case "2":
            cellStyle = 'background: #CAF982'
            break
          case "3":
            cellStyle = 'background: #81D3F8'
            break
          case "4":
            cellStyle = 'background: #FACD91'
            break
            default:
              cellStyle = ''
        }
        if (i == column.property) {
          return cellStyle
        }
      }
    },

版权声明:本文为qq_41206597原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。