element-ui表格多选,下方显示选中的数据

功能:表格多选时,下方需要显示选中的数据,下方取消选中的同时,表格也要随之取消选中;

1、row-key 绑定当前的id

2、使用this.$refs.dialogTable.toggleRowSelection(item, false);让对应的取消选中

<template>
  <div>
    <el-table
      height="300"
      :data="dialogTable"
      ref="dialogTable"
      :row-key="(row) => row.id"
      @selection-change="handleSelectionChangePop"
    >
      <el-table-column type="selection" width="55" />
    </el-table>

    <el-checkbox-group
      v-model="checkbox_group"
      v-for="(item, index) in selectionArr"
      :key="index"
      @change="getchegkbox"
    >
      <el-checkbox :label="item.id" name="type">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectionArr: [],
      checkbox_group: [],
    };
  },
  methods: {
    handleSelectionChangePop(val) {
      // 获取选中的数据
      this.selectionArr = val.map((item) => {
        return item;
      });
      // 让 el-checkbox 默认选中
      this.checkbox_group = this.selectionArr.map((item) => {
        return item.id;
      });
    },
    getchegkbox(e) {
      // 获取取消选中的 id
      const uncheckedItems = this.selectionArr.filter(
        (item) => !e.includes(item.id)
      );
      // 对取消选中的 id 执行其他操作
      for (const item of uncheckedItems) {
        this.$refs.dialogTable.toggleRowSelection(item, false);
      }
    },
  },
};
</script>

<style></style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值