600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > vue 使用ElementUI 在表格外设置全选的多选框

vue 使用ElementUI 在表格外设置全选的多选框

时间:2024-05-21 15:08:40

相关推荐

vue 使用ElementUI 在表格外设置全选的多选框

一、效果图

未选择状态:

未全选状态:

全选状态:

二、代码实现

data:

data(){return{//数据tableData:[],/*全选的问题 */multipleSelection: [],isIndeterminate: false,//表格外全选checkAll: false,}}

表格外全选功能的多选框:

<el-checkboxv-model="checkAll":indeterminate="isIndeterminate"@change="handleCheckAllChange"style="margin-right: 30px"><span class="qxText">全选本页(已选{{ this.multipleSelection.length }}个)</span></el-checkbox>

表格内的多选:

<el-tableref="multipleTable":data="tableData"tooltip-effect="dark"style="width: 100%":cell-style="{ 'font-size': '12px' }":header-cell-style="{background: '#f9f9f9','font-size': '12px','line-height': '18px',color: '#767989',}"@selection-change="handleSelectionChange"><el-table-column type="selection" width="40"> </el-table-column></el-table>

表格外全选方法:

// 点击外部全选handleCheckAllChange(val) {this.checkAll = val;var rows = this.tableData;var value = val ? rows : [];console.log(this.$refs.multipleTable);if (val) {rows.forEach((row) => {this.$refs.multipleTable.toggleRowSelection(row);});} else {this.$refs.multipleTable.clearSelection();}console.log(this.multipleSelection);}

表格内点击:

// 表格内点击多选框handleSelectionChange(val) {console.log(val);let checkedCount = val.length;this.checkAll = checkedCount === this.tableData.length;this.isIndeterminate =checkedCount > 0 && checkedCount < this.tableData.length;this.multipleSelection = val;},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。