Element-ui el-table 树形表格多选
2020-03-01 04:43
766 查看
Element-ui el-table 树形表格多选
- 关键方法
toggleRowSelection(row,flag) @select="rowSelect"(行选中) @select-all="selectAll"(全选)
- 页面代码
<el-table :data="dataList" ref="tableRef" highlight-current-row v-loading="loading" style="width: 100%;" size="small" row-key="id" @selection-change="selsChange" @select="rowSelect" @select-all="selectAll" :tree-props="{children: 'children', hasChildren: 'children.length>0'}" > > <el-table-column type="selection" width="50"></el-table-column> <el-table-column prop="menuName" label="菜单名称" sortable></el-table-column> <el-table-column prop="menuDes" label="菜单描述" sortable></el-table-column> <el-table-column prop="menuIcon" label="导航图标" sortable> <template slot-scope="scope"> <i :class="scope.row.menuIcon"></i> </template> </el-table-column> <el-table-column prop="menuPath" label="导航路径" sortable></el-table-column> <el-table-column prop="menuComponent" label="Vue文件路径" sortable></el-table-column> <el-table-column prop="menuLeaf" label="是否单节点" sortable> <template slot-scope="scope">{{scope.row.menuLeaf === 1?'是':'否'}}</template> </el-table-column> <el-table-column prop="menuHidden" label="是否隐藏" sortable> <template slot-scope="scope">{{scope.row.menuHidden === 1?'是':'否'}}</template> </el-table-column> <el-table-column label="状态"> <template slot-scope="scope"> <el-tag type="success" v-show="scope.row.menuStatus == 1" effect="dark" size="medium">正常</el-tag> <el-tag type="danger" v-show="scope.row.menuStatus == 2" effect="dark" size="medium">禁用</el-tag> </template> </el-table-column> <el-table-column label="操作"> <template slot-scope="scope"> <el-button type="danger" size="small" @click="changeMenuStatus(scope.row)" v-if="scope.row.menuStatus == 1" >禁用</el-button> <el-button type="success" size="small" @click="changeMenuStatus(scope.row)" v-if="scope.row.menuStatus == 2" >启用</el-button> <el-button type="primary" size="small" @click="toUpdate(scope.row)">修改</el-button> </template> </el-table-column> </el-table>
- js代码
toggleSelection(rows, flag) { if (rows) { rows.forEach(row => { this.$refs.tableRef.toggleRowSelection(row, flag); }); } else { this.$refs.tableRef.clearSelection(); } }, rowSelect(selection, row) { if (selection.indexOf(row) > -1 && row.menuLevel === 1) { this.toggleSelection(row.children, true); } if (selection.indexOf(row) === -1 && row.menuLevel === 1) { this.toggleSelection(row.children, false); } if (selection.indexOf(row) > -1 && row.menuLevel === 2) { let s = this.dataList.filter(item => { if (item.id === row.menuPid) { return item; } }); this.toggleSelection(s, true); } }, selectAll(selection) { var flag = false; // 默认 为全不选 selection.forEach(item => { if (item.menuLevel === 1) { flag = true; this.toggleSelection(item.children, true); } }); if (!flag) { this.toggleSelection(); } },
- 目前能实现我想要的结果,可能跟你们需求不太一致,可自行修改
效果如下:
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- element ui table(表格)点击一行展开
- element-ui表格多选实现翻页选择记忆功能
- 利用 Vue 和 element 的实现table增、删、改表格数据的模糊匹配搜索
- Element-ui(el-table、el-pagination)实现表格分页
- vue+element UI实现树形表格
- 五:Vue之ElementUI 表格Table与分页Pagination组件化
- vue组件之 列表滚动条左移时前2列悬浮固定 类似于 Element-Table表格-固定列
- vuejs+element UI table表格中实现禁用部分复选框的方法
- element UI table表格组件使用[超级完整功能]
- vue-cli-element-ui-table-表格分页功能切换数据后@current-change失效的解决方案
- VueJS Element-UI el-select 多选情况下绑定值的问题
- element-ui的table表格控件表头与内容列不对齐问题
- vue将指定区域的表格数据或element-ui中el-table的数据单笔或多笔批量导出excel
- Element-Ui组件(二十二)Table 表格
- element-ui表格table增删改查时判断是哪一行
- vue2.0基于vue-cli,element-ui饿了么vue前端开源项目制作vue的树形table,treeTable
- vue elementUI table表格数据 滚动懒加载的实现方法
- vue-cli-+-element-ui-树形表格(多级表格折腾小计)
- VUE2.0 ElementUI2.0表格el-table自适应高度的实现方法
- Element-ui table中过滤条件变更表格内容的方法