Quantcast
Viewing all articles
Browse latest Browse all 82127

Sort Columns with Numbers and Empty Cells

I noticed that sorting cells numerically works pretty well unless you have empty cells mixed in with integers in your column. This plug-in makes sure that empty cells get sorted lower than 0.

jQuery.fn.dataTableExt.oSort['numWithNull-asc'] = function(a,b) {
var x = parseInt(a);
var y = parseInt(b);
return ((isNaN(x) || x < y) ? -1 : ((isNaN(y) || x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numWithNull-desc'] = function(a,b) {
var x = parseInt(a);
var y = parseInt(b);
return ((isNaN(x) || x < y) ? 1 : ((isNaN(y) || x > y) ? -1 : 0));
};

Viewing all articles
Browse latest Browse all 82127

Trending Articles