el-table样式总结—持续更新

本文总结了Element UI中el-table组件的样式定制技巧,包括如何为特定表头添加样式、如何使用span-method进行单元格合并,以及如何为特定表格单元格设置样式。通过示例代码,展示了rowIndex和columnIndex的用法,以及返回css样式的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.el-table标签的header-cell-style给指定的表头添加样式

 :header-cell-style="getRowClass"

 getRowClass ({ row, column, rowIndex, columnIndex }) { 
        
               if ((rowIndex === 0 && columnIndex === 0) || (rowIndex === 1 && (columnIndex === 0 || columnIndex === 1))) {
                    return 'background:#c90a5b;color:#fff;text-align:center;font-size:15px;font-weight:550;';
                } else {
                    return '';
                }
            
            }
       

rowIndex===0是第一行,columnIndex===0是第一列。 return ' css样式 '

2. el-table标签的:span-method合并单元格,不包含表头

:span-method="rowSpanMethod"

if里面可以自定义,return[0,0]表示不合并。return[行数,列数]

   rowSpanMethod({ row, column, rowIndex, columnIndex }) {
            /**
             * 表格合并
             * row 表格每一行的数据
             * column 表格每一列的数据
             * rowIndex 表格的行索引,不包括表头,从0开始
             * columnIndex 表格的列索引,从0开始
             */
            if (this.areaShow || this.teamShow) {
                if (columnIndex === 0) {
                    if (rowIndex % areaAndTeamRowCount === 0) { 
                        return [areaAndTeamRowCount, 1];
                    } else {
                        return [0, 0];
                    }
                }
            }
        }

3. el-table标签的:cell-style给特定表格添加样式 ,return cellStyle + ' css样式'

  :cell-style="cellStyle"
  cellStyle({ row, column, rowIndex, columnIndex }) {
       if (diffRow === 0 && rowIndex % temCount === 0) {
                if (cellValue < this.standardParameter.stoveRunCount) {
                    return cellStyle + 'color:#f00;';
                }
           }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值