el-table使用type=“expand”根据数据条件隐藏展开按钮

一:添加className
<el-table :data="tableData" border :loading="loading" :row-class-name="getRowClass" @expand-change="expandchange">
   <el-table-column type="expand">
      <template #default="props">
        {{ props.row.expanded ? '收起' : '展开' }}
      </template>
   </el-table>

// 使用getRowClass针对每一行添加类由于我的是根据内容的pcObj长度只有一个隐藏,多个显示。根据自己条件进行更改

const getRowClass = (row: any) => {
  console.log(row);
  let data = row.row;
  let res = [];
  if (data.pcObj.length > 1) {
    res.push('row-expand-has');
    return res;
  } else {
    res.push('row-expand-unhas');
    return res;
  }
}
操作完在控制台可以发现row-expand-unhas已添加成功

二:添加CSS样式隐藏row-expand-unhas的按钮
.row-expand-unhas .el-table__expand-column {
    pointer-events: none;
}
.row-expand-unhas .el-table__expand-column .el-icon {
    visibility: hidden;
}

可能在项目中会存在添加样式不起作用,这时就需要用到样式穿透 :deep()

:deep(.row-expand-unhas .el-table__expand-column) {
  pointer-events: none;
}

:deep(.row-expand-unhas .el-table__expand-column .el-icon) {
  visibility: hidden;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值