Vue -- element-ui 所有数据前台排序
2021-04-09 13:27
标签:数据 load ice ati this rda hang OLE scope 特别感谢那篇文章,给人家点了赞忘记留链接了,所以没留原文链接,再次感谢! Vue -- element-ui 所有数据前台排序 标签:数据 load ice ati this rda hang OLE scope 原文地址:https://www.cnblogs.com/lisaShare/p/13374082.htmldata(){
return {
loading: true,
pageNum: 1,
pageSize: 10,
total: 4,
tableData: []
}
},
methods: {
sort_change(column) { // column是个形参,具体查看element-ui文档
// console.log(column)
this.pageNum = 1 // return to the first page after sorting
if (column.prop === ‘recordDate‘) {
this.tableData = this.tableData.sort(this.sortFun(column.prop, column.order === ‘ascending‘));
// console.log(this.tableData);
} else if (column.prop === ‘followNum‘) {
this.tableData = this.tableData.sort(this.sortFun(column.prop, column.order === ‘ascending‘));
// console.log(this.tableData);
}else if (column.prop === ‘unFollowNum‘) {
this.tableData = this.tableData.sort(this.sortFun(column.prop, column.order === ‘ascending‘));
// console.log(this.tableData);
}else if(column.prop === ‘currdateFollowNum‘) {
this.tableData = this.tableData.sort(this.sortFun(column.prop, column.order === ‘ascending‘));
// console.log(this.tableData);
}
// this.showed_data = this.tableData.slice(0, this.pageSize) // 排序完显示到第一页
console.log(‘Finished‘)
},
sortFun: function (attr, rev) {
//第一个参数传入info里的prop表示排的是哪一列,第二个参数是升还是降排序
if (rev == undefined) {
rev = 1;
} else {
rev = (rev) ? 1 : -1;
}
return function (a, b) {
a = a[attr];
b = b[attr];
if (a b) {
return rev * 1;
}
return 0;
}
},
}