Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82109

Sort Columns with Numbers and Empty Cells

$
0
0
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 82109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>