I'm using the jQuery DataTables plugin, and the title-numeric custom sort plugin. The sort works ALMOST. I have a table with the td tags containing a hidden span element like so...
<td><span title="5">DATA HERE</span></td>
<td><span title="4">DATA HERE</span></td>
<td><span title="2">DATA HERE</span></td>
<td><span title="17">DATA HERE</span></td>
<td><span title="10">DATA HERE</span></td>
Using the hidden title numeric sort on those columns, when in DESC order I get the cells with the title in the following order
5,4,2,17,10
Where I would have expected it to sort as
17,10,5,4,2
Any ideas as to what could be wrong? Here is how I'm initializing the table...
$(document).ready(function() {
$('#myTable').dataTable({
"oLanguage": { "sSearch": "Filter Data" },
"iDisplayLength": -1,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sType": "title-numeric" }
]
});
});
Plugin code added before table is initialized is here:
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"title-numeric-pre": function ( a ) {
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
return parseFloat( x );
},
"title-numeric-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"title-numeric-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );