el-table 设置只能单选效果(2)

2022-03-03  本文已影响0人  我是七月

el-table中添加:header-cell-class-name="cellClass"表头增加class函数

<el-table
  :data="tableData"
  ref="table"
  border
  :header-cell-class-name="cellClass"
>
   <el-table-column
    type="selection"
    align="center"
   />
</el-table>

methods中增加对应函数,可根据是否单选(this.radio)来控制全选框显示与否

this.radio 根据不同的业务场景可以动态控制

methods: {
   cellClass(row){
     if (row.columnIndex === 0 && this.radio) {
       return 'disableheadselection'
     }
   }
}

添加css样式隐藏选框
因为添加的class属于在el-table的表头中,/deep/需要写在刚增加的class名前才会生效.(若需要在scoped中修改elementUI中的样式,则需要在选择器前面加上/deep/才会生效)

<style lang="scss" scoped>
    /deep/ .disableheadselection > .cell .el-checkbox__inner {
      display: none;
    }
<style>

上一篇 下一篇

猜你喜欢

热点阅读