Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 排序多列单击单列排序';带数据表的头部_Jquery_Sorting_Datatable_Numbers - Fatal编程技术网

Jquery 排序多列单击单列排序';带数据表的头部

Jquery 排序多列单击单列排序';带数据表的头部,jquery,sorting,datatable,numbers,Jquery,Sorting,Datatable,Numbers,我正在尝试使用用于jQuery的DataTable插件(最新版本)对2列进行排序。有了这个,就可以上船了 $('#example').dataTable( { "aaSorting": [ [2,'asc'], [3,'asc'] ], }); 我有点困难排序2列点击。例如,当用户单击“相册”时,该表没有对TrackNo列进行排序。 我的桌子看起来像这样: ------------------------------------- | Album | Tra

我正在尝试使用用于jQuery的DataTable插件(最新版本)对2列进行排序。有了这个,就可以上船了

 $('#example').dataTable( {
     "aaSorting": [ [2,'asc'], [3,'asc'] ],
});
我有点困难排序2列点击。例如,当用户单击“相册”时,该表没有对TrackNo列进行排序。 我的桌子看起来像这样:

-------------------------------------
| Album             | TrackNo       |
-------------------------------------
| MyAlbum 2010      | 1 out of 12   |
| MyAlbum 2010      | 9 out of 12   |
| MyAlbum 2010      | 10 out of 12  |
| MyAlbum 2010      | 4 out of 12   |
| MyAlbum 2010      | 2 out of 12   |
| MyAlbum 2010      | 12 out of 12  |
-------------------------------------
另一个问题是,当我对列“Album”排序时,TrackNo列按以下顺序排序:1、10、12、2、4、9

我注意到,可以通过以下方式更改DataTable的排序方式:

jQuery.fn.dataTableExt.oSort['numericstring-case-asc']  = function(x,y) {
    return ((x < y) ? -1 : ((x > y) ?  1 : 0));
};

jQuery.fn.dataTableExt.oSort['numericstring-case-desc'] = function(x,y) {
    return ((x < y) ?  1 : ((x > y) ? -1 : 0));
};
jQuery.fn.dataTableExt.oSort['numericstring-case-asc']=函数(x,y){
回报率((xy)?1:0);
};
jQuery.fn.dataTableExt.oSort['numericstring-case-desc']=函数(x,y){
回报率((xy)?-1:0);
};
我的问题是:如何对TrackNo列进行排序,使其以良好的顺序显示曲目,而不在每个曲目前面添加零?
如何在单击时对2列进行排序?

使用以下代码创建符合您要求的dataTableExt-oSort方法:

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "hybrid-asc": function(x, y) {
        if (!isNaN(parseInt(x)) && !isNaN(parseInt(y))) {
            x = parseInt(x);
            y = parseInt(y);
        }
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    },
    "hybrid-desc": function(x, y) {
        if (!isNaN(parseInt(x)) && !isNaN(parseInt(y))) {
            x = parseInt(x);
            y = parseInt(y);
        }
        return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    }
});

|

使用以下代码创建符合您要求的dataTableExt oSort方法:

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "hybrid-asc": function(x, y) {
        if (!isNaN(parseInt(x)) && !isNaN(parseInt(y))) {
            x = parseInt(x);
            y = parseInt(y);
        }
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    },
    "hybrid-desc": function(x, y) {
        if (!isNaN(parseInt(x)) && !isNaN(parseInt(y))) {
            x = parseInt(x);
            y = parseInt(y);
        }
        return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    }
});

|

哇,工作得很有魅力,非常感谢你,特等大师!:)节日快乐!哇,工作得很有魅力,非常感谢你,大师!:)节日快乐!