element跨分頁操作選擇詳解
更新時間:2020年06月29日 11:45:16 作者:沫熙瑾年
這篇文章主要為大家詳細介紹了element跨分頁操作選擇,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了element跨分頁操作選擇的具體代碼,供大家參考,具體內(nèi)容如下
業(yè)務(wù)需求:在批量導(dǎo)出或者批量刪除的時候會涉及到跨分頁導(dǎo)出或者批量刪除,這是你會發(fā)現(xiàn),當(dāng)你選擇后點擊分頁,發(fā)現(xiàn)之前選擇的數(shù)據(jù)已經(jīng)沒有了,現(xiàn)在就是要滿足分頁點擊分頁后原始數(shù)據(jù)保留
<template>
<div>
<el-table
:data="tableData"
tooltip-effect="dark"
style="width: 100%;"
header-align="left"
border
ref="table"
row-key="serviceDateId"
@selection-change="handleSelectionChange"
@row-dblclick="toDetail"
@sort-change="sortChange"
>
<el-table-column type="selection" el-table-column width="50" fixed="left"></el-table-column>
<el-table-column label="序號" width="80" fixed="left">
<template slot-scope="{row,$index}">
<span>{{$index + 1}}</span>
</template>
</el-table-column>
<el-table-column label="服務(wù)日期" prop="serviceDate" sortable="custom" min-width="120" ></el-table-column>
<el-table-column label="服務(wù)對象" prop="vsoName" min-width="120"></el-table-column>
<el-table-column label="身份證號" prop="idCard" sortable="custom" min-width="200"></el-table-column>
<el-table-column label="服務(wù)內(nèi)容" prop="serviceContentName" min-width="200"></el-table-column>
<el-table-column label="服務(wù)結(jié)果" prop="serviceResultName" min-width="100"></el-table-column>
<el-table-column label="志愿者" prop="volunteerName" sortable="custom" min-width="120" show-overflow-tooltip></el-table-column>
<el-table-column label="志愿者所屬組織" prop="objName" min-width="200" show-overflow-tooltip></el-table-column>
<el-table-column fixed="right" label="操作" width="150" header-align="center">
<template slot-scope="{row,$index}">
<span @click="handleEdit(row)" class="table-btn" v-has="{class: '編輯'}">編輯</span>
<span @click="handleRemove($index, row)" class="table-btn"
v-has="{class: '刪除'}">刪除</span>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="form.pageNum"
:limit.sync="form.pageSize"
@pagination="getData(form)"
/>
</div>
</template>
<script>
export default {
data(){
return{
ruleForm: {
username: '',
password:''
},
form: {
pageNum: 1, // 分頁頁數(shù)
pageSize: 10, // 分頁數(shù)量
},
multipleSelection: [], //多選的行數(shù)據(jù)
multipleSelectionAll:[],// 當(dāng)前頁選中的數(shù)據(jù)
idKey: 'idCard',
}
},
methods: {
setSelectRow() {
if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) {
return;
}
// 標(biāo)識當(dāng)前行的唯一鍵的名稱
let idKey = this.idKey;
let selectAllIds = [];
let that = this;
this.multipleSelectionAll.forEach(row=>{
selectAllIds.push(row[idKey]);
})
this.$refs.table.clearSelection();
for(var i = 0; i < this.tableData.length; i++) {
if (selectAllIds.indexOf(this.tableData[i][idKey]) >= 0) {
// 設(shè)置選中,記住table組件需要使用ref="table"
this.$refs.table.toggleRowSelection(this.tableData[i], true);
}
}
},
// 記憶選擇核心方法
changePageCoreRecordData () {
// 標(biāo)識當(dāng)前行的唯一鍵的名稱
let idKey = this.idKey;
let that = this;
//如果總記憶中還沒有選擇的數(shù)據(jù),那么就直接取當(dāng)前頁選中的數(shù)據(jù),不需要后面一系列計算
if (!this.multipleSelectionAll.length) {
this.multipleSelectionAll = this.multipleSelection;
return;
}
// 總選擇里面的key集合
let selectAllIds = [];
this.multipleSelectionAll.forEach(row=>{
selectAllIds.push(row[idKey]);
})
let selectIds = []
// 獲取當(dāng)前頁選中的id
this.multipleSelection.forEach(row=>{
selectIds.push(row[idKey]);
// 如果總選擇里面不包含當(dāng)前頁選中的數(shù)據(jù),那么就加入到總選擇集合里
if (selectAllIds.indexOf(row[idKey]) < 0) {
that.multipleSelectionAll.push(row);
}
})
let noSelectIds = [];
// 得到當(dāng)前頁沒有選中的id
this.tableData.forEach(row=>{
if (selectIds.indexOf(row[idKey]) < 0) {
noSelectIds.push(row[idKey]);
}
})
noSelectIds.forEach(id=>{
if (selectAllIds.indexOf(id) >= 0) {
for(let i = 0; i< that.multipleSelectionAll.length; i ++) {
if (that.multipleSelectionAll[i][idKey] == id) {
// 如果總選擇中有未被選中的,那么就刪除這條
that.multipleSelectionAll.splice(i, 1);
break;
}
}
}
})
},
// 多選的行數(shù)據(jù)
handleSelectionChange(val) {
this.multipleSelection = val
setTimeout(()=>{
this.changePageCoreRecordData();
}, 50)
},
// 獲取表格數(shù)據(jù)
getData(form) {
let parmas = _.cloneDeep(form);
parmas.liveArea = typeof(parmas.liveArea) === 'object'?parmas.liveArea.join(''):parmas.liveArea;
recordSearch(form).then(res => {
if (res.rows) {
this.tableData = res.rows;
this.total = res.total;
this.exportData = _.cloneDeep(form);
setTimeout(()=>{
this.setSelectRow();
}, 50)
}
else {
this.tableData = [];
this.total = 0;
}
})
}
},
mounted(){
this.getData(this.form)
}
}
</script>
<style lang="sass" scoped>
</style>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 利用vue + element實現(xiàn)表格分頁和前端搜索的方法
- Vue+element-ui 實現(xiàn)表格的分頁功能示例
- 利用vue和element-ui設(shè)置表格內(nèi)容分頁的實例
- vue + element-ui的分頁問題實現(xiàn)
- vue 基于element-ui 分頁組件封裝的實例代碼
- vue+element tabs選項卡分頁效果
- vue仿element實現(xiàn)分頁器效果
- Vue+ElementUI table實現(xiàn)表格分頁
- Vue+Element UI+Lumen實現(xiàn)通用表格分頁功能
- element表格翻頁第2頁從1開始編號(后端從0開始分頁)
相關(guān)文章
vue實現(xiàn)動態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動畫
這篇文章主要介紹了vue實現(xiàn)動態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動畫方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
vue在頁面和方法中如何通過遍歷對象獲取對象的鍵(key)和值(value)
這篇文章主要介紹了vue在頁面和方法中如何通過遍歷對象獲取對象的鍵(key)和值(value)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05

