<script type="text/javascript" id="js">
jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
var y = b.match(/title="*(-?[0-9\.]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
var y = b.match(/title="*(-?[0-9\.]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#myid').dataTable(
{
"aoColumns": [
null,
null,
null,
{ "sType": "title-numeric" },
null,
null,
null,
{ "sType": "title-numeric" },
null,
null,
null
],
// "bPaginate": true,
// "sPaginationType": "full_numbers",
// "bFilter": false,
// "sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
// "bStateSave": true,
// "fnDrawCallback": updateTableFuncts(),
}
);
runSomethings();
} );
function runSomethings() {
alert("somethings changed "); }
}
</script>
allan said: Syntax errors on lines 4-5 and others
jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9]+)/)[1];
var y = b.match(/title="*(-?[0-9]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9]+)/)[1];
var y = b.match(/title="*(-?[0-9]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
oTable = $('#example').dataTable({
"aoColumns": [
null,
null,
{ "sType": "title-numeric" },
{ "sType": "title-numeric" },
null,
null
],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaSorting": [ ]
});
});
<tr><td bgcolor="#fefefe" title="1"> </td><td bgcolor="#fefefe" title="1"> </td><td bgcolor="#fdae61" title="0.18518825"> </td><td bgcolor="#fefefe" title="1"> </td><td bgcolor="#fefefe" title="1"> </td><td><a href="http://www.broad.mit.edu/gsea/msigdb/cards/AAAGACA,MIR-511">AAAGACA,MIR-511</a></td></tr>Following is what you see in the row 1 of the debugger datatable
["", "", "", "", "", "<a href=\"http://www.broad.mit.edu/gsea/msigdb/cards/AAAGACA,MIR-511\">AAAGACA,MIR-511</a>"]
<td bgcolor="#fefefe" title="1">
This definitely would not work due to html page becoming ugly. Numbers are only for sorting (numbers not to be shown in the cell)
put the numeric data inside the cell.
This might work. However, with my very limited knowledge of javascript I am not sure about how it can be done for my case. Can you please tell me what changes I need to make?
use a custom data gatherer for the sort:
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.