jquery datatables排序忽略空值 [英] jquery datatables sorting neglect null value

查看:203
本文介绍了jquery datatables排序忽略空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表和jQuery来制作不错的可排序表。我现在要排序一个值。该值是一个数值。但是它也可能不可用,所以在这一点上,我会回发一个破折号。



当我现在对这个列进行排序时,带有破折号的所有行都在顶部。并且显示了具有值1,3,6,8,10的行。我如何更改这一点,以便破折号( - )始终位于表的底部?



目前我放置了最大数量,底部。但是,我不希望向用户显示该值。所以我需要一个隐藏的排序列或其他排序方法。



提前感谢

解决方案

参见: http://jsfiddle.net/CYubV/



表中的第一列像普通列一样工作;



尝试自定义排序,如下所示:

  $。fn.dataTableExt.oSort ['nullable-asc'] = function(a,b){
if(a ==' - ')
return 1;
else if(b ==' - ')
return -1;
else
{
var ia = parseInt(a);
var ib = parseInt(b);
return(ia< ib)? -1:((ia> ib)≈1:0);
}
}

$ .fn.dataTableExt.oSort ['nullable-desc'] = function(a,b){
if(a ==' - ')
return 1;
else if(b ==' - ')
return -1;
else
{
var ia = parseInt(a);
var ib = parseInt(b);
return(ia&ib)? -1:((ia }
}

$('#table')。dataTable({
bPaginate:false,
bFilter:false,
aoColumns:[
null,
{bSortable:true,sType:nullable}
],
});


I'm using datatables and jQuery for making nice sortable tables. I now want to sort the rows an a value. This value is a numeric value. But it can also be not available, so at that point I will echo a dash.

When I now sort this column, all rows with the dash are on top. And than the rows with value 1, 3, 6, 8, 10 are shown. How do I change this so that the dash (-) are always on bottom of the table?

At the moment I put in a maximum number, what puts them on the bottom. However I don't want this value to be shown to the user. So I need a hidden sort column, or a other sorting method.

Thanks in advance!

解决方案

See this: http://jsfiddle.net/CYubV/

The first column in the table works like a normal column; the second column works like you ask.

Try custom sorting, something like this:

$.fn.dataTableExt.oSort['nullable-asc'] = function(a,b) {
    if (a == '-')
        return 1;
    else if (b == '-')
        return -1;
    else
    {
        var ia = parseInt(a);
        var ib = parseInt(b);
        return (ia<ib) ? -1 : ((ia > ib) ? 1 : 0);
    }
}

$.fn.dataTableExt.oSort['nullable-desc'] = function(a,b) {
    if (a == '-')
        return 1;
    else if (b == '-')
        return -1;
    else
    {
        var ia = parseInt(a);
        var ib = parseInt(b);
        return (ia>ib) ? -1 : ((ia < ib) ? 1 : 0);
    }
}

$('#table').dataTable( {
    "bPaginate": false,
    "bFilter": false,
    "aoColumns": [
            null,
            {"bSortable": true, "sType": "nullable"}
                ],
} );

这篇关于jquery datatables排序忽略空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆