el-table复选框单选及回显

复选框单选

<el-table
    :date="list"
    :selection-change = "selectChange"
    @select = "selectRow" //主要
    @select-all = "selectAll" //主要
    ref = "tableInfo"//主要
  >
<el-table-column type = "selection" with = "40"/>
...
</el-table>
data(){
  return{
    selected:[]
  }
}

JS

selectChange(data){
  this.selected = data;
  //this.selected = data.map((item) => item.deptId);
}

selectRow(selection, row){
  if(selection.length > 1){
    let del_row = selection.shift();
    this.$refs.tableInfo.toggleRowSelection(del_row,false);
  }
}

selectAll(selection){
  if(selection.length > 1){
    selection.length = 1;
  }
}

回显

const {a, b} = this;
b.forEach((row) => {
  if(b.depeId === a.deptId){
    this.$nextTick(() =>{
      this.$refs.tableInfo.toggleRowSelection(row,true); //主要
    })
  }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
el-tableElement UI 中的一个表格组件,而复选框回显是指在 el-table 中使用复选框进行多选操作后,再次打开表格时,已选中的项能够显示为选中状态。 要实现 el-table 复选框回显,可以按照以下步骤进行操作: 1. 在 el-table 的列定义中,添加一个带有 type 属性为 "selection" 的列,用于显示复选框。 2. 在 el-table 的数据源中,为每一条数据添加一个属性,用于表示该项是否被选中。 3. 在 el-table 的模板中,使用 v-model 指令绑定每一行数据的选中状态。 4. 在 el-table 的 mounted 钩子函数中,根据数据源中的选中状态,将已选中的项设置为选中状态。 下面是一个示例代码: ```html <template> <el-table :data="tableData" style="width: 100%"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { name: '张三', age: 20, selected: true }, { name: '李四', age: 25, selected: false }, { name: '王五', age: 30, selected: true }, ], }; }, mounted() { this.tableData.forEach((item) => { if (item.selected) { this.$refs.multipleTable.toggleRowSelection(item, true); } }); }, }; </script> ``` 在上述示例中,tableData 数组中的每一项都添加了一个 selected 属性,用于表示该项是否被选中。在 mounted 钩子函数中,通过遍历 tableData 数组,将 selected 为 true 的项设置为选中状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值