sSort, sSortDataType, errors in documentation and sorting not working [Fixed]
sSort, sSortDataType, errors in documentation and sorting not working [Fixed]

Hi!
First of all, dataTables are great! Excellent tool and very powerfull. However, last night I was trying to sort some data by columns that have formatted data in it. Namely, columns has point and comma separators for grouping and decimals. After few hours I ended making my own sorting function that just strips all that's not digit and sort it like that. But... how to call that? I tried all sorts of combination of sSort and sSortDataType parameters always following documentation that say about sSort:
[quote]The type allows you to specify how the data for this column will be sorted. Four types (string, numeric, date and html (which will strip HTML tags before sorting)) are currently available.[/quote]
It's not working. Then I searched forum and here http://datatables.net/forums/discussion/7492/formatted-number-sorting-with-some-text-data found allan asking user: "Have you set the sType for the column to be "formatted-num"?" This contradict documentation. But I was glad I found it. I tried it and it worked! I used this definition
[code]"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [0, 2, 3] },
][/code]
and it worked like a charm. I was soooo happy. Then, I just copied this piece of code to another table with the data formatted in the same way, but there it's not working. Not working at all. I mean, my natural sort function is not even called. I was thinking it's because those two tables are in the same page, so I turned off original one, and tried, nothing. Then I thought it's because second one uses pagination, so I tried with [code]"bPaginate": false[/code], and nothing. I tried turning off footer callback, nothing. Now I'm desperate since I get it to work, only to find out it's working partially. What am I doing wrong?
Code for table that WORKS:
[code]
$('#total').dataTable({
"aaSorting": [[ 0, "asc" ]],
"bPaginate": false,
"bJQueryUI": true,
"oLanguage": {
"sProcessing": "Procesiranje u toku...",
"sLengthMenu": "Prikaži _MENU_ elemenata",
"sZeroRecords": "Nije pronaden nijedan rezultat",
"sInfo": "Prikaz _START_ do _END_ od ukupno _TOTAL_ elemenata",
"sInfoEmpty": "Prikaz 0 do 0 od ukupno 0 elemenata",
"sInfoFiltered": "(filtrirano od ukupno _MAX_ elemenata)",
"sInfoPostFix": "",
"sSearch": "Pretraga:",
"sUrl": "",
"oPaginate": {
"sFirst": "Pocetna",
"sPrevious": "Prethodna",
"sNext": "Sledeća",
"sLast": "Poslednja"
}
},
"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [0, 2, 3] },
]
});
[/code]
Code for table that DON'T WORK:
[code]
$('#resultsOdDo').dataTable({
"aaSorting": [[ 0, "asc" ]],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"oLanguage": {
"sProcessing": "Procesiranje u toku...",
"sLengthMenu": "Prikaži _MENU_ elemenata",
"sZeroRecords": "Nije pronaden nijedan rezultat",
"sInfo": "Prikaz _START_ do _END_ od ukupno _TOTAL_ elemenata",
"sInfoEmpty": "Prikaz 0 do 0 od ukupno 0 elemenata",
"sInfoFiltered": "(filtrirano od ukupno _MAX_ elemenata)",
"sInfoPostFix": "",
"sSearch": "Pretraga:",
"sUrl": "",
"oPaginate": {
"sFirst": "Pocetna",
"sPrevious": "Prethodna",
"sNext": "Sledeća",
"sLast": "Poslednja"
},
"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [1] },
]
},
"fnFooterCallback": function( footerRow, tableWhole, paginationStart,
paginationStartEnd, tableDisplayed ) {
setTimeout("500");
var celije = $(footerRow).children();
celije[1].innerHTML = $("#ukupanBrojLokala").html();
celije[3].innerHTML = $("#ukupnoTrajanje").html();
},
});
[/code]
Can somebody please tell me what I missed!
Thanks!
First of all, dataTables are great! Excellent tool and very powerfull. However, last night I was trying to sort some data by columns that have formatted data in it. Namely, columns has point and comma separators for grouping and decimals. After few hours I ended making my own sorting function that just strips all that's not digit and sort it like that. But... how to call that? I tried all sorts of combination of sSort and sSortDataType parameters always following documentation that say about sSort:
[quote]The type allows you to specify how the data for this column will be sorted. Four types (string, numeric, date and html (which will strip HTML tags before sorting)) are currently available.[/quote]
It's not working. Then I searched forum and here http://datatables.net/forums/discussion/7492/formatted-number-sorting-with-some-text-data found allan asking user: "Have you set the sType for the column to be "formatted-num"?" This contradict documentation. But I was glad I found it. I tried it and it worked! I used this definition
[code]"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [0, 2, 3] },
][/code]
and it worked like a charm. I was soooo happy. Then, I just copied this piece of code to another table with the data formatted in the same way, but there it's not working. Not working at all. I mean, my natural sort function is not even called. I was thinking it's because those two tables are in the same page, so I turned off original one, and tried, nothing. Then I thought it's because second one uses pagination, so I tried with [code]"bPaginate": false[/code], and nothing. I tried turning off footer callback, nothing. Now I'm desperate since I get it to work, only to find out it's working partially. What am I doing wrong?
Code for table that WORKS:
[code]
$('#total').dataTable({
"aaSorting": [[ 0, "asc" ]],
"bPaginate": false,
"bJQueryUI": true,
"oLanguage": {
"sProcessing": "Procesiranje u toku...",
"sLengthMenu": "Prikaži _MENU_ elemenata",
"sZeroRecords": "Nije pronaden nijedan rezultat",
"sInfo": "Prikaz _START_ do _END_ od ukupno _TOTAL_ elemenata",
"sInfoEmpty": "Prikaz 0 do 0 od ukupno 0 elemenata",
"sInfoFiltered": "(filtrirano od ukupno _MAX_ elemenata)",
"sInfoPostFix": "",
"sSearch": "Pretraga:",
"sUrl": "",
"oPaginate": {
"sFirst": "Pocetna",
"sPrevious": "Prethodna",
"sNext": "Sledeća",
"sLast": "Poslednja"
}
},
"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [0, 2, 3] },
]
});
[/code]
Code for table that DON'T WORK:
[code]
$('#resultsOdDo').dataTable({
"aaSorting": [[ 0, "asc" ]],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"oLanguage": {
"sProcessing": "Procesiranje u toku...",
"sLengthMenu": "Prikaži _MENU_ elemenata",
"sZeroRecords": "Nije pronaden nijedan rezultat",
"sInfo": "Prikaz _START_ do _END_ od ukupno _TOTAL_ elemenata",
"sInfoEmpty": "Prikaz 0 do 0 od ukupno 0 elemenata",
"sInfoFiltered": "(filtrirano od ukupno _MAX_ elemenata)",
"sInfoPostFix": "",
"sSearch": "Pretraga:",
"sUrl": "",
"oPaginate": {
"sFirst": "Pocetna",
"sPrevious": "Prethodna",
"sNext": "Sledeća",
"sLast": "Poslednja"
},
"aoColumnDefs": [
{"sSortDataType": "natural-asc", "sType": "natural", "aTargets": [1] },
]
},
"fnFooterCallback": function( footerRow, tableWhole, paginationStart,
paginationStartEnd, tableDisplayed ) {
setTimeout("500");
var celije = $(footerRow).children();
celije[1].innerHTML = $("#ukupanBrojLokala").html();
celije[3].innerHTML = $("#ukupnoTrajanje").html();
},
});
[/code]
Can somebody please tell me what I missed!
Thanks!
This discussion has been closed.
Replies
But I think that documentation should be updated, and also in aTarget documentation should be added that part what arguments can be passed to reference columns. I would just copy explanation of targets from here http://datatables.net/usage/columns since that negative number can be confusing.
Thanks for great tool!