I'm trying to sort numbers like these:
<1E-8
0.000027
0.000061
0.0018
0.0094
<8.64e-12
0.049
'<' means that the true value is less than the number given.
Here is my "descent function," which I have a very high confidence in:
$.fn.dataTableExt.oSort['scientific-desc'] = function(a,b) {
var x = a.replace(/^[<>]/g,"");
var y = b.replace(/^[<>]/g,"");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
}
And I defined an "ascent function" similarly:
$.fn.dataTableExt.oSort['scientific-asc'] = function(a,b) {
var x = a.replace(/^[<>]/g,"");
var y = b.replace(/^[<>]/g,"");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
I've played with just about everything in the initialization code and with the above sorting functions but nothing seems to be able to get the numbers to sort correctly in the table. The numbers <1E-8 always tend to stay together and so do the ones with a lowercase 'e'.
The code to initialize the dataTable is as follows. It's probably worth noting that this is code is called inside of an AJAX call:
$.get('xyz.json',
function(data) {
// deal with json data
// get it ready for dataTable
// ...
$('.table').dataTable( {
"sScrollY": "200px",
"aoColumns": [
null,
null,
{"bSortable": true, "sType": "scientific"},
{"bSortable": false}
],
"aaSorting": [ [2,'asc'] ],
"bPaginate": false,
"bFilter": false,
"iDisplayLength": 5,
"bRetrieve": true,
"bDestroy": true
} );
});