Tocas: Table 无法根据数据类型排列

Created on 14 Jan 2018  ·  2Comments  ·  Source: teacat/tocas

这是我用于的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()
}

image

无法排列整数类型

image
无法排列整数+逗号类型

image
无法排列日期

✨ 功能追加 🐛 已證實 Bug 💡 改進提案 💬 討論 📜 JavaScript

Most helpful comment

也許還能讓 ts().tablesort() 能夠傳個 function 進去來自訂排序? 🤔

All 2 comments

也許還能讓 ts().tablesort() 能夠傳個 function 進去來自訂排序? 🤔

我觉得可以,如果用户没有传任何函数,就以字符串来排列。

但这对有些用户来说并不友好。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

toby3d picture toby3d  ·  4Comments

YamiOdymel picture YamiOdymel  ·  5Comments

toby3d picture toby3d  ·  3Comments

toby3d picture toby3d  ·  3Comments

racterub picture racterub  ·  4Comments