el-table表格实现多选功能(全选/指定选中/取消选中)

2713 ℃

vue项目开发中,如何实现el-table表格全选、指定选中、取消选中等功能,下面web建站小编给大家详细介绍一下具体实现代码!

template代码

<template>
  <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="age"
      label="年龄"
      show-overflow-tooltip>
    </el-table-column>
  </el-table>
  <div style="margin-top: 20px">
    <el-button @click="toggleSelection([tableData[3]])">切换第四行的选中状态</el-button>
    <el-button @click="toggleSelection()">取消选择</el-button>
  </div>
</template>

script代码

<script>
  export default {
    data() {
      return {
        tableData: [],
        multipleSelection: []
      }
    },

    methods: {
      //如果定义了指定选中项,点击选中指定项,否则取消选中
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    }
  }
</script>

el-table合并行的通用方法(附js代码)

el-table利用:row-style="rowClass"设置指定行变色

el-table表格显示selection多选时对某些复选框设置禁止选中

el-table实现拖拽行排序sortablejs

el-dialog中获取el-table组件的ref值报undefined错误!

标签: el-table, el-table多选, selection

上面是“el-table表格实现多选功能(全选/指定选中/取消选中)”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_4082.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css如何利用flex实现响应式布局
js如何获取时间戳并转换成日期
laydate时间插件获取时间范围
织梦dede调用父级栏目链接和名称
面试题:JavaScript中10道面试题及答案