el-table//置頂數據不參與排序


 

 

sortChangefirst(column){
//不參與排序的數組
// if (this.$refs.table) this.$refs.table.clearSort()
let freeGood = []
// //參與排序的數組
let elseFree = []
// //fieldName 為對應列的prop
let fieldName = column.prop
let sortingType = column.order
// //降序
if (sortingType === "descending"){
this.newTabledata.forEach(item => {
//在整個tableData中找到不參與排序的所有數據
if (item.keyStatus===1) {
//不參與排序的所有數據加到數組中
freeGood.push(item)
}
else {
//參與排序的數據
elseFree.push(item)
}
})
//進行排序
this.newTabledata = elseFree.sort((a, b) => parseFloat(b[fieldName]) - parseFloat(a[fieldName]))
//如果要排序字符串
//可以對fieldName進行判斷進行如下操作
//this.tableData = elseFree.sort((a, b) => b[fieldName].localeCompare(a[fieldName]))
}else{
this.newTabledata.forEach(item => {
if (item.keyStatus===1) {
freeGood.push(item)
}else {
elseFree.push(item)
}
})
this.newTabledata = elseFree.sort((a, b) => parseFloat(a[fieldName]) - parseFloat(b[fieldName]))
}
this.newTabledata=freeGood.concat(this.newTabledata)
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM