asSorting - am I doing something wrong, or is this a bug?

asSorting - am I doing something wrong, or is this a bug?

duncdunc Posts: 8Questions: 0Answers: 0
edited August 2012 in General
I'm using dataTables to retrieve information from my PHP script.

This works fully - apart from a minor technical hitch.

By default, I'd like my data to be ordered by Datetime, descending - i.e. most recent items first. However, I would still like users to be able to sort by Datetime ascending too, if they click the column header.

To achieve this, I'm using the following code:

[code] $('#content div').html( '' );
var oTable = $('#example').dataTable( {
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "dataTables.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var sDirectionClass;

if ( aData[6].indexOf("img") > 0 ) {
sDirectionClass = "new";
if ( row % 2 !== 0 )
sDirectionClass = "new_odd";
} else {
sDirectionClass = "std";
}

row++;

$(nRow).addClass( sDirectionClass );
return nRow;
},
"aoColumns": [
/* UID */ { "bSearchable": false,
"bVisible": false },
/* Datetime */ { "asSorting": [ "desc" ] },
/* Staff Name */ null,
/* Room */ null,
/* Reason */ null,
/* Urgency */ null,
/* Processed? */ null ]
} );[/code]

What actually happens is this: there is no default sorting and when I click the Datetime column header (to sort), it will only sort in descending order. If I remove the asSorting on Datetime and replace it with a simple null, the sorting works both ways - but obviously the default sorting isn't then by Datetime.

Is this a bug, or am I doing something wrong?

Replies

  • duncdunc Posts: 8Questions: 0Answers: 0
    edited August 2012
    I've managed to reproduce the problem on JSBin, although I apologise for the poor formatting etc.

    http://live.datatables.net/exorec/3

    You'll see that the Datetime column *isn't* sorted by default, and that if you click on its column header, it can't be sorted in ascending order.
  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Try this: http://live.datatables.net/exorec/4/edit

    I've added aaSorting and put `asc` back into the asSorting array.

    Allan
  • duncdunc Posts: 8Questions: 0Answers: 0
    Working, thanks Allan! Superb plugin and support, by the way.
  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    :-) Thanks!

    Allan
This discussion has been closed.