这是我用于的PHP代码
// check a sample value
var sampleval = this.latestreport[0][col]
// true then reverse
this.sortcol = !this.sortcol
// Sort number
var sampleval = this.latestreport[0][col]
this.sortcol = !this.sortcol
// Sort number
if(!isNaN(sampleval)){
this.latestreport.sort(function(a,b) {
return a[col] - b[col]
});
}
// Sort datetime
else if(new Date(sampleval).getTime()){
this.latestreport.sort(function(a,b){
return new Date(b.date) - new Date(a.date);
});
}
// Sort alphabetically
else{
this.latestreport.sort(function(a,b){
return (a[col] < b[col]) ? -1 : 1;
});
}
// reverse
if(this.sortcol){
this.latestreport.reverse()
}

无法排列整数类型

无法排列整数+逗号类型

无法排列日期
也許還能讓 ts().tablesort() 能夠傳個 function 進去來自訂排序? 🤔
我觉得可以,如果用户没有传任何函数,就以字符串来排列。
但这对有些用户来说并不友好。
Most helpful comment
也許還能讓 ts().tablesort() 能夠傳個 function 進去來自訂排序? 🤔