strange sorting problem
strange sorting problem
johncscott
Posts: 14Questions: 0Answers: 0
Using datatables 1.9.4
I have this initialisation
[code]
$(document).ready(function () {
$.fn.dataTable.defaults.aLengthMenu = [[1, 5, 10, 25, 50, -1], [1, 5, 10, 25, 50, "All"]];
$('#eventstats').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "/js/datatables/swf/copy_csv_xls_pdf.swf",
"aButtons": [ "copy", "csv", "print" ] },
"sPaginationType": "bootstrap",
"sLengthMenu": "_MENU_ records per page",
"bProcessing": true,
"aoColumnDefs": [
{ "mRender": function (data, type, row) { return '' + data + ''; }, "aTargets": [1] },
{ "sType": "numeric" ,"mRender": function (data, type, row) { return data + '%'; }, "aTargets": [2] },
{ "mRender": function (data, type, row) { return formatMoney(data); }, "aTargets": [4, 6, 8] }
]
});
[/code]
The problem I am having is with the
{ "sType": "numeric" ,"mRender": function (data, type, row) { return data + '%'; }, "aTargets": [2] },
The data is from a JSON source and this column holds just a number eg 1.45 or 45.23 which then uses mrender to show this as a percentage.
With the type set as "numeric" as above when I click the sort only the second row of the table changes and the rest of the rows are unaffected.
Why would that be?
I have this initialisation
[code]
$(document).ready(function () {
$.fn.dataTable.defaults.aLengthMenu = [[1, 5, 10, 25, 50, -1], [1, 5, 10, 25, 50, "All"]];
$('#eventstats').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "/js/datatables/swf/copy_csv_xls_pdf.swf",
"aButtons": [ "copy", "csv", "print" ] },
"sPaginationType": "bootstrap",
"sLengthMenu": "_MENU_ records per page",
"bProcessing": true,
"aoColumnDefs": [
{ "mRender": function (data, type, row) { return '' + data + ''; }, "aTargets": [1] },
{ "sType": "numeric" ,"mRender": function (data, type, row) { return data + '%'; }, "aTargets": [2] },
{ "mRender": function (data, type, row) { return formatMoney(data); }, "aTargets": [4, 6, 8] }
]
});
[/code]
The problem I am having is with the
{ "sType": "numeric" ,"mRender": function (data, type, row) { return data + '%'; }, "aTargets": [2] },
The data is from a JSON source and this column holds just a number eg 1.45 or 45.23 which then uses mrender to show this as a percentage.
With the type set as "numeric" as above when I click the sort only the second row of the table changes and the rest of the rows are unaffected.
Why would that be?
This discussion has been closed.
Replies
Is not numeric though. You want to do a conditional return based on the data type requested. This blog post has more details (and less mistakes than I'll make typing this with a baby in one hand :-) ): http://datatables.net/blog/Orthogonal_data
Allan
and best of luck with the baby
you may need it :)