Element official website explanation
row-class-name | The callback method for the row's className, or a string can be used to set a fixed className for all rows. | Function({row, rowIndex})/String |
row-style | The callback method of the row's style can also use a fixed Object to set the same Style for all rows. | Function({row, rowIndex})/Object |
cell-class-name | The callback method of the cell's className, you can also use a string to set a fixed className for all cells. | Function({row, column, rowIndex, columnIndex})/String |
cell-style | The callback method of the cell's style can also use a fixed Object to set the same Style for all cells. | Function({row, column, rowIndex, columnIndex})/Object |
1. Change the color of a cell according to conditions
<el-table :data="rowData" border size="mini" :cell-style="styleBack">
<el-table-column label="row1">11111</el-table-column>
<el-table-column property="" label="row2">22222</el-table-column>
<el-table-column property="" label="row3">33333</el-table-column>
<el-table-column property="" label="row3">44444</el-table-column>
<el-table-column property="" label="row3">55555</el-table-column>
<el-table-column property="" label="row3">66666</el-table-column>
</el-table>
rowData: [
{ id: 1, num: 2 },
{ id: 2, num: 3 },
{ id: 3, num: 4 },
],
styleBack({ row, column, rowIndex, columnIndex }) {
if (columnIndex == 1 && row.num > 3) {
return { backgroundColor: "#0c87ef" };
}else if(columnIndex == 1){
return { backgroundColor: "#FDD56A" };
}
},
result