el-table表格在表头和数据行添加图标、处理数据

ゞ 浴缸里的玫瑰 2021-07-27 02:58 983阅读 0赞

通过header插槽自定义表头:

  1. <template slot="header" slot-scope="scope">
  2. ...
  3. </template>

可以通过scope.row.columnName 获取单元项数据进行数据处理:

  1. <template slot-scope="scope">
  2. <span :class="1<2 ? 'red-font' : 'blue-font' ">
  3. {
  4. {formatDate(scope.row.temperature)}} ℃
  5. </span>
  6. </template>

如图:

  1. <el-table :data="currentCabinData"
  2. style="width: 100%" stripe border height="100">
  3. <el-table-column prop="name"
  4. label="设备仓" fixed>
  5. </el-table-column>
  6. <el-table-column prop="temperature" >
  7. <!-- 表头项 -->
  8. <template slot="header"
  9. slot-scope="scope">
  10. <span class="mgrinr1">温度</span>
  11. <d2-icon name="thermometer-2"
  12. style="font-size: 18px;" />
  13. </template>
  14. <!-- 行数据项 -->
  15. <template slot-scope="scope">
  16. {
  17. { scope.row.temperature }} <!-- scope.row.prop -->
  18. <span v-show="scope.row.temperature"
  19. class="unit-color"></span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="humidity">
  23. <template slot="header"
  24. slot-scope="scope">
  25. <span class="mgrinr1">湿度</span>
  26. <d2-icon name="tint"
  27. style="font-size: 18px;" />
  28. </template>
  29. <template slot-scope="scope">
  30. {
  31. { scope.row.humidity }}
  32. <span v-show="scope.row.humidity"
  33. class="unit-color">%</span>
  34. </template>
  35. </el-table-column>
  36. </el-table>

上述el-table中关键字可以实现border纵向边框、stripe斑马线、固定表头或表列、多级表头、最小表高度、行单选、多选、数据过滤、展开行数据、树形数据懒加载、自定义表头、行尾统计、合并行或列等效果

使用header-cell-style属性修改表头样式,可为函数或对象:

使用cell-style属性更改表格中某个单元格的样式,可为函数或对象:

  1. <!-- html -->
  2. <el-table :header-cell-style="rowClass" :cell-style="cellStyle">
  3. </el-table>
  4. //在method里面写上方法
  5. cellStyle({row, column, rowIndex, columnIndex}){
  6. if(rowIndex === 1 && columnIndex === 2){ //指定坐标
  7. return 'background:pink'
  8. }else{
  9. return ''
  10. }
  11. }

发表评论

表情:
评论列表 (有 0 条评论,983人围观)

还没有评论,来说两句吧...

相关阅读