Vue -- 为表格的特定行或特定列增加样式 & 表格不显示表头
程序员文章站
2022-06-07 22:06:48
...
可见,效果是加在第一列和第三列上的
<el-table :data="basicInfo" border style="width:100%;margin-top:20px;" highlight-current-row
:show-header="false" :cell-style="cellStyle">
<el-table-column prop="col1Name" align="right" min-width="5" width="200px"> </el-table-column>
<el-table-column prop="col1Value" align="left" min-width="7"> </el-table-column>
<el-table-column prop="col2Name" align="right" min-width="5" width="200px"> </el-table-column>
<el-table-column prop="col2Value" align="left" min-width="7"> </el-table-column>
</el-table>
cellStyle({row, column, rowIndex, columnIndex}){
// 奇数列新增样式
if(columnIndex % 2 == 0){
return 'background:#2C8DF4;color:#FFFFFF'
}
}
JSONObject obj = new JSONObject();
JSONArray basicArray = new JSONArray();
JSONObject basicCol1 = new JSONObject();
basicCol1.put("col1Name", "应用名称");
basicCol1.put("col1Value", "AAA");
basicCol1.put("col2Name", "类别");
basicCol1.put("col2Value", "监控运维");
basicArray.add(basicCol1);
JSONObject basicCol2 = new JSONObject();
basicCol2.put("col1Name", "版本");
basicCol2.put("col1Value", "1.0");
basicCol2.put("col2Name", "使用者");
basicCol2.put("col2Value", "admin");
basicArray.add(basicCol2);
JSONObject basicCol3 = new JSONObject();
basicCol3.put("col1Name", "申请日期");
basicCol3.put("col1Value", "2020-04-30 09:00:00");
basicCol3.put("col2Name", "到期日期");
basicCol3.put("col2Value", "2021-04-30 09:00:00");
basicArray.add(basicCol3);
JSONObject basicCol4 = new JSONObject();
basicCol4.put("col1Name", "创建时间");
basicCol4.put("col1Value", "2020-04-30 09:00:00");
basicCol4.put("col2Name", "描述");
basicCol4.put("col2Value", "1111");
basicArray.add(basicCol4);
obj.put("basicInfo", basicArray);
this.write(JSON.toJSONString(obj));
注1::show-header=“false” 表示不显示表头
上一篇: angular 表格内容滚动
下一篇: vue中循环表格数据给最后一行添加样式