asSorting - am I doing something wrong, or is this a bug?
asSorting - am I doing something wrong, or is this a bug?
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?
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?
This discussion has been closed.
Replies
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.
I've added aaSorting and put `asc` back into the asSorting array.
Allan
Allan