How to reset/clear sorting
How to reset/clear sorting
My application gets table data from a query and displays it with no initial sorting by DataTables ("aaSorting":[ ]). Table sorting is enabled and works fine.
But I would like to be able to reset to the initial state: rows in query order, no sort column(s) set, and no sort classes applied. Is there a way I can do that?
But I would like to be able to reset to the initial state: rows in query order, no sort column(s) set, and no sort classes applied. Is there a way I can do that?
This discussion has been closed.
Replies
There isn't really a way to do this at the moment. I think the thing to do would be to create an API function ( http://datatables.net/development/api ) called fnSortingReset() which would empty the aiDisplay and aiDisplayMaster arrays (and aaSorting) and then recalculate them based on aoData...
Sorry - I know this sounds a little complicated, but with the number of support requests in the forum at the moment and paid support, I don't really have time to write the plug-in myself :-(. I've got it in my to-do list now - but if you take a stab at it, please to post back!
Regards,
Allan
[code]
$('#ClearSort').click( function() { oTable.fnSort( [ ] ); });
[/code]
You may be able to add a redraw or some other function that would put the data back in the original order in which it was loaded.
Regards,
Allan
[code]
var oTable = $('#data_table').dataTable();
$('.sorting, .sorting_asc, .sorting_desc').dblclick(function(){
oTable.fnSort([]);
return false;
});
[/code]
This will make all column headers that are sortable clear all sorting when the user double clicks any sortable column header.
- Peter
Allan