How to get values of the current sort column index and direction from [aoData]?
How to get values of the current sort column index and direction from [aoData]?
deathtospam
Posts: 10Questions: 0Answers: 0
I'm grabbing data from the server for each datatable page and it's working properly. However, each time an AJAX request is submitted -- for a new page of data, or when a column is clicked to re-sort the data -- I need to know what the current sort column index (0..n) and direction (ascending/descending) are. I know that these values are available in aoData, which I have access to, but I don't know what the syntax is to retrieve them.
Help?
Help?
This discussion has been closed.
Replies
Take a look here:
http://datatables.net/usage/server-side
I think you'll find what your looking for under:
bool bSortable_(int) Indicator for if a column is flagged as sortable or not on the client-side
int iSortingCols Number of columns to sort on
int iSortCol_(int) Column being sorted on (you will need to decode this number for your database)
string sSortDir_(int) Direction to be sorted - "desc" or "asc".
[code]
table.fnSettings().aaSorting
[/code]
That is DataTable's internal store. It should be treated as read only. If you want to set it, use fnSort .
In 1.10 I'm going to look at making fnSort a getter/setter.
Allan
[code]
$("#MyTable thead tr:eq(0)").on("click", "th", function(event){
fGetSortInfo();
});
function fGetSortInfo() {
// Returns a value of [5, "desc", 0] every time.
var sortInfo = $("#MyTable").dataTable().fnSettings().aaSorting;
}
[/code]
I'm wondering if I'm binding fGetSortInfo() in the wrong way or place. Is there an event I can bind to after the table is done updating?
Allan