Sorting problem after upgrade from 1.7.5
Sorting problem after upgrade from 1.7.5
I upgraded datatables from 1.7.5 to 1.9.2 and without changing the javascript setup, the sorting of the columns is reversed.
The first two columns of data are the date in the format Y-m-d H:i:s and the second column is in the format l, F d, Y @ H:i:s.
I'm expecting the newest date to be first and the oldest date to be last.
Would anyone have insight into this?
Much appreciated.
Jonathan
[code]
jQuery(document).ready(function() {
var oTable;
oTable = jQuery('.dataGrid').dataTable( {
'aLengthMenu': [[25, 50, 100, -1], [25, 50, 100,'All']],
'iDisplayLength': 25,
'sPaginationType': 'full_numbers',
'sDom': '<"top"lfi>rt<"bottom"pT<"clear">',
'sFilter': false,
'bJQueryUI': false,
'bAutoWidth': false,
'bStateSave': false,
'bProcessing': true,
'bInfo': true,
'oTableTools': { 'sSwfPath': '../../images/datatables/copy_csv_xls_pdf.swf' },
'aoColumnDefs': [
{ 'aTargets': [ 0 ], 'asSorting': ['desc','asc'], 'bVisible': false },
{ 'aTargets': [ 1 ], 'iDataSort': 0 }
]
} );
} );
[/code]
The first two columns of data are the date in the format Y-m-d H:i:s and the second column is in the format l, F d, Y @ H:i:s.
I'm expecting the newest date to be first and the oldest date to be last.
Would anyone have insight into this?
Much appreciated.
Jonathan
[code]
jQuery(document).ready(function() {
var oTable;
oTable = jQuery('.dataGrid').dataTable( {
'aLengthMenu': [[25, 50, 100, -1], [25, 50, 100,'All']],
'iDisplayLength': 25,
'sPaginationType': 'full_numbers',
'sDom': '<"top"lfi>rt<"bottom"pT<"clear">',
'sFilter': false,
'bJQueryUI': false,
'bAutoWidth': false,
'bStateSave': false,
'bProcessing': true,
'bInfo': true,
'oTableTools': { 'sSwfPath': '../../images/datatables/copy_csv_xls_pdf.swf' },
'aoColumnDefs': [
{ 'aTargets': [ 0 ], 'asSorting': ['desc','asc'], 'bVisible': false },
{ 'aTargets': [ 1 ], 'iDataSort': 0 }
]
} );
} );
[/code]
This discussion has been closed.
Replies
I've created a little table which I think accurately represents your scenario here: http://live.datatables.net/amujuw/2/edit .
So there are a number of things going on here:
1. Your asSorting on the first column is almost irrelevant, since the user can't select to sort on that column, so it is asSorting on the second column that is important here. You will want to swap that around I think. Interesting that this worked in 1.7.5 - that might be a "bug" that I've fixed since then! (certainly if it didn't work that way I would consider it a bug).
2. The initial sort of the table is given by aaSorting, regardless of the asSorting etc of the column. By default aaSorting is: [[0,'asc']] - which is why you are getting the initial sort the opposite way from expected.
This is a modification of my example from above with the two changes suggested made, and, if I understand correctly, I think this is how you want it to work:
http://live.datatables.net/amujuw/3/edit .
I'm sorry you've found a discrepancy between the versions - this kind of thing shouldn't happen (or if there is a breaking change, at least be mentioned in the release notes!), so there is something slightly unexpected, or a fix relative to the old version has been implemented which causes this discrepancy.
Regards,
Allan
Yup. It's all good now. I've put in the new lines. Everything works!
Thanks for your help!
Jonathan Perlman
My pleasure. Good to hear that works for you - thanks for letting me know. Thanks also for picking up the DataTables support!
Regards,
Allan