strange sorting problem

strange sorting problem

johncscottjohncscott Posts: 14Questions: 0Answers: 0
edited September 2013 in DataTables 1.9
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?

Replies

  • fearednerdfearednerd Posts: 44Questions: 0Answers: 0
    I was fiddling with my table with your situation. I had the same problem. The thing that fixed it for me was to set bSortable as true in that column definition.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > return data + '%';

    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
  • johncscottjohncscott Posts: 14Questions: 0Answers: 0
    edited September 2013
    ahaaa - that makes perfect sense - thank you for the blog link :)

    and best of luck with the baby
    you may need it :)
This discussion has been closed.