Default sort not working with either method

Default sort not working with either method

jpretoriusjpretorius Posts: 2Questions: 0Answers: 0
edited February 2012 in General
I'm trying to use asSorting in aoColumnDefs to set the default sort order when the page loads, but for some reason it isn't working. With that not working I also tried to use asSorting in aoColumns and that didn't work either. For some reason when the page first loads the first column is sorted in ascending order.

By the way, I've tried to use aTargets of 0, 1 and _all without a change in behaviour. I've also tested multiple browsers.

Can anyone help me figure this one out?

My initialising code is as follows:

[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 100,
"sAjaxSource": "scripts/server_processing.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "sTable", "value": "audit" } );
aoData.push( { "name": "sIndexColumn", "value": "idaudit" } );
aoData.push(
{ "name": "aColumns[]", "value": "datetime" },
{ "name": "aColumns[]", "value": "action" },
{ "name": "aColumns[]", "value": "detail" }
);
},
"oLanguage": {
"sLengthMenu": 'Display '+
'100'+
'250'+
'500'+
'All'+
' entries per page'
},
"aoColumnDefs": [
{ "asSorting": [ "desc", "asc" ], "aTargets": [ 0 ] }
],
"aoColumns": [
{ "asSorting": [ "desc", "asc" ] },
null,
null
]
} );
} );
[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > For some reason when the page first loads the first column is sorted in ascending order.

    I think you want aaSorting - that specifies the initial sort and is independent of the asSorting parameters for the columns.

    Allan
  • jpretoriusjpretorius Posts: 2Questions: 0Answers: 0
    Aha, that's exactly what I want - thank you for the pointer!
This discussion has been closed.