jquery datatables排序忽略空值 [英] jquery datatables sorting neglect null value
问题描述
当我现在对这个列进行排序时,带有破折号的所有行都在顶部。并且显示了具有值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屋!