element UI表格使用cell-style改变单元格样式

【例子1】 

// 调用方法的部分为:
<el-table
:cell-style="timeStyle"
>

// 要修改样式的部分为:
<el-table-column
  label="创建时间"
  :formatter="startTime"
  width="150">

// 方法:
methods:
// 改变表格中时间的字体样式:调小
timeStyle(column) {
if(column.columnIndex === 2 || column.columnIndex === 4) {
return "font-size: 2px"

【例子2】

<el-table
                    :data="testCases"
                    stripe
                    border
                    size="small"
                    row-key="id"
                    :max-height="maxHeight"
                    @selection-change="selectionChange"
                    @filter-change="filterChange"
                    :cell-style="cellStyle"
                    ref="table">
               <el-table-column
                        show-overflow-tooltip
                        width="100"
                        label="测试结果"
                        prop="testResult"
                        sortable>
                    <template slot-scope="scope">
                        <input class="custom_input" v-if="scope.row.id===idFocused" v-model="scope.row.testResult"
                               @blur="idFocused=''" @keyup.enter="idFocused = ''">
                        <span v-else>{{scope.row.testResult}}</span>
                    </template>
                </el-table-column>




 cellStyle({row, column, rowIndex, columnIndex}) {//根据测试结果动态调整单元格样式,成功-绿色,失败-红色,不支持-黄色
                let cellStyle;
                switch (row.testResult) {
                    case '成功':
                        cellStyle = 'background: green;color:white';
                        break;
                    case '失败':
                        cellStyle = 'background: red;color:white';
                        break;
                    case '不支持':
                        cellStyle = 'background: #aaa;color:white';
                        break;
                    default:
                        cellStyle = '';
                }
                if (column.label == '测试结果')
                    return cellStyle;
            }

 

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huayang183

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值