fnSortListener
fnSortListener
danideidea
Posts: 6Questions: 0Answers: 0
Hi Allan,
I'm trying to use fnSortListener to use the callback that provides, but the click only sort in an ascendent way: no matter how many times you click, it always sort ascendently, and arrow stays the same.
What I've done is something like this: oTable.fnSortListener(document.getElementById("th_type"), 4). I don't know if is that enough or I'm missing something.
Thanks.
Regards.
I'm trying to use fnSortListener to use the callback that provides, but the click only sort in an ascendent way: no matter how many times you click, it always sort ascendently, and arrow stays the same.
What I've done is something like this: oTable.fnSortListener(document.getElementById("th_type"), 4). I don't know if is that enough or I'm missing something.
Thanks.
Regards.
This discussion has been closed.
Replies
I've just tried the following on my zero config example ( http://datatables.net/examples/basic_init/zero_config.html ) and it seems to operate as expected with the following code:
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable();
oTable.fnSortListener( $('.full_width')[0], 1 );
} );
[/code]
Could you give us a link to your page where it isn't working?
Allan
But, the first parameter, the node, it's a reference to th in the datatable, isn't it? I've got this:
...
...
Type
...
...
And my datatable's definition:
var oTable = $('#table').dataTable({
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bProcessing": true,
"bJQueryUI": true,
"bPaginate": false,
"bFilter": true,
"bInfo": true,
"aaSorting": [[5,'asc']],
"sDom": "<'H'fl>T<'clear'>rt<'F'ip>",
"aoColumns": [
...
...
{ "sWidth": null, "bSortable": true }, //type
...
...
],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
nRow.setAttribute("id", aData[1]);
// Bold the grade for all 'A' grade browsers
if ( aData[0] == "10" ) {
$(nRow).addClass("A");
} else if (aData[0] == "20") {
$(nRow).addClass("B");
} else if (aData[0] == "30") {
$(nRow).addClass("C");
}
return nRow;
}
});
new FixedHeader( oTable );
And then the call to fnSortListener (inside document ready):
oTable.fnSortListener($("#th_type")[0], 4, function() {
alert(oTable.fnSettings().aaSorting);
});
That returns always the same (4,desc,1) and I don't know why.
D'you see something weird?
Thanks again.
So do you need to add the sort listener at all? I'd guess that the TH already one on it.
Allan
Thank you.
I have what sounds like a similar scenario where I have a column that needs to be treated as numeric. However it also contains cells with 'n/a' in them. Instead of being sorted together they are ignored in the sort so I get.
1,000
1,100
n/a
1,105
1,200
instead of
n/a
1,000
1,100
1,105
1,200
[quote]danideidea said: What I really need to do is to change data before the sort takes place, and then sort it.[/quote]
Is there a setting I've missed or do I need to write a custom function as @danidea would like to?
Allan