el-table控制type=“expand“展开列 根据条件显示或隐藏展开按钮

1,通过样式控制 首先定义行class样式 在组件中需通过样式穿透

::v-deep {
  .row-expand-unhas .el-table__expand-column {
    pointer-events: none;
  }
  .row-expand-unhas .el-table__expand-column .el-icon {
    visibility: hidden;
  }
}

2,行判断数据条件 添加class

    <el-table
      ref="tableRef"
      :data="tableData"
      style="width: 100%"
      row-key="id"
      border
      :height="tableHeight"
      :row-class-name="getRowClass"
      @expand-change="handleExpandChange"
    >
      <el-table-column type="expand">
        <template #default="props">
....
        </template>
      </el-table-column>


    // 根据是否合计行判断是否隐藏展开按钮
    getRowClass({row}) {
      const res = []
      if (row.sector !== '合计') {
        res.push('row-expand-has')
        return res
      } else {
        res.push('row-expand-unhas')
        return res
      }
    },

3.最终效果

转载请说明出处内容投诉
CSS教程网 » el-table控制type=“expand“展开列 根据条件显示或隐藏展开按钮

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买