element跨分頁(yè)操作選擇詳解
本文實(shí)例為大家分享了element跨分頁(yè)操作選擇的具體代碼,供大家參考,具體內(nèi)容如下
業(yè)務(wù)需求:在批量導(dǎo)出或者批量刪除的時(shí)候會(huì)涉及到跨分頁(yè)導(dǎo)出或者批量刪除,這是你會(huì)發(fā)現(xiàn),當(dāng)你選擇后點(diǎn)擊分頁(yè),發(fā)現(xiàn)之前選擇的數(shù)據(jù)已經(jīng)沒有了,現(xiàn)在就是要滿足分頁(yè)點(diǎn)擊分頁(yè)后原始數(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="序號(hào)" 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ù)對(duì)象" prop="vsoName" min-width="120"></el-table-column>
<el-table-column label="身份證號(hào)" 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, // 分頁(yè)頁(yè)數(shù)
pageSize: 10, // 分頁(yè)數(shù)量
},
multipleSelection: [], //多選的行數(shù)據(jù)
multipleSelectionAll:[],// 當(dāng)前頁(yè)選中的數(shù)據(jù)
idKey: 'idCard',
}
},
methods: {
setSelectRow() {
if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) {
return;
}
// 標(biāo)識(shí)當(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)識(shí)當(dāng)前行的唯一鍵的名稱
let idKey = this.idKey;
let that = this;
//如果總記憶中還沒有選擇的數(shù)據(jù),那么就直接取當(dāng)前頁(yè)選中的數(shù)據(jù),不需要后面一系列計(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)前頁(yè)選中的id
this.multipleSelection.forEach(row=>{
selectIds.push(row[idKey]);
// 如果總選擇里面不包含當(dāng)前頁(yè)選中的數(shù)據(jù),那么就加入到總選擇集合里
if (selectAllIds.indexOf(row[idKey]) < 0) {
that.multipleSelectionAll.push(row);
}
})
let noSelectIds = [];
// 得到當(dāng)前頁(yè)沒有選中的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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 利用vue + element實(shí)現(xiàn)表格分頁(yè)和前端搜索的方法
- Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
- 利用vue和element-ui設(shè)置表格內(nèi)容分頁(yè)的實(shí)例
- vue + element-ui的分頁(yè)問題實(shí)現(xiàn)
- vue 基于element-ui 分頁(yè)組件封裝的實(shí)例代碼
- vue+element tabs選項(xiàng)卡分頁(yè)效果
- vue仿element實(shí)現(xiàn)分頁(yè)器效果
- Vue+ElementUI table實(shí)現(xiàn)表格分頁(yè)
- Vue+Element UI+Lumen實(shí)現(xiàn)通用表格分頁(yè)功能
- element表格翻頁(yè)第2頁(yè)從1開始編號(hào)(后端從0開始分頁(yè))
相關(guān)文章
vue實(shí)現(xiàn)動(dòng)態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動(dòng)畫
這篇文章主要介紹了vue實(shí)現(xiàn)動(dòng)態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動(dòng)畫方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vue在頁(yè)面和方法中如何通過遍歷對(duì)象獲取對(duì)象的鍵(key)和值(value)
這篇文章主要介紹了vue在頁(yè)面和方法中如何通過遍歷對(duì)象獲取對(duì)象的鍵(key)和值(value)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
Vue3進(jìn)階主題Composition API使用詳解
這篇文章主要為大家介紹了Vue3進(jìn)階主題Composition API使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
解決vue3?defineProps?引入定義的接口報(bào)錯(cuò)
這篇文章主要為大家介紹了解決vue3?defineProps?引入定義的接口報(bào)錯(cuò)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05

