element table默认全选,可选择全不选

  • row-key 行数据的 Key,用来优化 Table 的渲染
  • selection-change 当选择项发生变化时会触发该事件
  • reserve-selection 仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key)
  • toggleRowSelection 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)

在这里插入图片描述

<el-radio-group
  v-model="radio"
  class="tips_radio"
  @change="radioChange"
>
  <el-radio :label="true">全选</el-radio>
  <el-radio :label="false">非全选</el-radio>
</el-radio-group>
<el-table
  ref="multipleTable2"
  :data="tableRow"
  tooltip-effect="dark"
  border
  style="width: 100%"
  :row-key="getOpenKey"
  @selection-change="changeFunOpen"
>
  <el-table-column
    type="selection"
    width="55"
    :reserve-selection="true"
  >
  </el-table-column>
</el-table>
// 表格列表
getAssets() {
  getAsset({})
    .then((res) => {
      this.tableRow = res.data
      // 默认全选
      this.$nextTick(() => {
        for (let i = 0; i < this.tableRow.length; i++) {
          this.$refs.multipleTable2.toggleRowSelection(
            this.tableRow[i],
            true
          )
        }
      })
    })
    .catch((err) => {
      console.log(err)
    })
},
// 全选
radioChange(val) {
  if (val == false) {
    this.$refs.multipleTable2.clearSelection()
  } else {
    // 默认全选
    this.$nextTick(() => {
      for (let i = 0; i < this.tableRow.length; i++) {
        this.$refs.multipleTable2.toggleRowSelection(this.tableRow[i], true)
      }
    })
  }
},
 // 指定一个key标识这一行的数据
 getOpenKey(row) {
   return row.id
 },
 // 获取勾选
 changeFunOpen(val) {
   this.checkOpen = []
   this.checkOpen = val
 },
 // 确定
 operationOk() {
   if(this.checkOpen.length != 0){
     this.$router.push({ path: '/net' })
   }else{
     this.$message({
       type:'error',
       message:'请至少选择一个运维设备'
     })
   }
 },
  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值