el-table解決過濾導(dǎo)致選中的丟失的問題
el-table解決過濾導(dǎo)致選中的丟失
場景:
當(dāng)前選中了A,B,C,D四條數(shù)據(jù),我現(xiàn)在想找出Z這條數(shù)據(jù),過濾之后,ABCD就是不可見,但是我還是選中了,此時(shí)選中Z之后ABCD就選中不了了,此時(shí)我們需要選中ABCD并且選中Z。
第一步:el-table的設(shè)置
重點(diǎn)是ref="kpiTableRef",@select="handleSelectKpi",@select-all="handleSelectKpi"
注意:select和select-all需要對應(yīng)一個(gè)相同的方法的名稱。
filteredKpiOptions是計(jì)算屬性的來的。
<el-table ref="kpiTableRef" style="margin: 0 10px 0 0" :data="filteredKpiOptions" :height="450" v-loading="kpiTableLoading" :header-cell-style="{ background: '#eef1f6', color: '#606266' }" highlight-row @select="handleSelectKpi" @select-all="handleSelectKpi" > <el-table-column type="selection" width="55" /> <el-table-column prop="name" label="xxx名稱" :show-overflow-tooltip="true" /> </el-table>
第二步:設(shè)置計(jì)算屬性
待過濾名稱
<el-form :inline="true" :model="filterKpiModel"> <el-form-item label="xx名稱" prop="name"> <el-input v-model="filterKpiModel.kpiName" placeholder="過濾xxx名稱" clearable/> </el-form-item> </el-form>
計(jì)算屬性
- - kpiOptions是全部的數(shù)據(jù)
- - filteredKpiOptions 是過濾返回的數(shù)據(jù)
filteredKpiOptions() { // 刷新選中 this.setKpiSelStatus(); if (!this.filterKpiModel.kpiName) { return this.kpiOptions; } return this.kpiOptions.filter((data) => data.kpiName.includes(this.filterKpiModel.name) ); }
第三步:設(shè)置選中的數(shù)據(jù)
setKpiSelStatus() { const vm = this; let currentKpiIds = []; for (let selKpi of vm.selKpiList) { if (!currentKpiIds.includes(selKpi.kpiId)) { currentKpiIds.push(selKpi.kpiId); } } for (let kpi of vm.kpiOptions) { vm.$set(kpi, 'kpiId', kpi.id); if (currentKpiIds.includes(kpi.id)) { vm.$set(kpi, 'isCheck', true); vm.$nextTick(() => { vm.$refs.kpiTableRef.toggleRowSelection(kpi, true); }); } else { vm.$set(kpi, 'isCheck', false); } } },
到此這篇關(guān)于el-table解決過濾導(dǎo)致選中的丟失的文章就介紹到這了,更多相關(guān)el-table過濾導(dǎo)致選中的丟失內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Kindeditor單獨(dú)調(diào)用單圖上傳增加預(yù)覽功能的實(shí)例
下面小編就為大家?guī)硪黄狵indeditor單獨(dú)調(diào)用單圖上傳增加預(yù)覽功能的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07Javascript isArray 數(shù)組類型檢測函數(shù)
在日常開發(fā)中,我們經(jīng)常需要判斷某個(gè)對象是否是數(shù)組類型的,在js中檢測對象類型的常見的方法有幾種.2009-10-10分享幾個(gè)JavaScript運(yùn)算符的使用技巧
這篇文章主要介紹了分享幾個(gè)JavaScript運(yùn)算符的使用技巧,幫助大家更好的理解和學(xué)習(xí)使用JavaScript,感興趣的朋友可以了解下2021-04-04