Order of events - DT:Order() needs to fire before DT:Ajax
Order of events - DT:Order() needs to fire before DT:Ajax
pingcrosby
Posts: 29Questions: 4Answers: 1
Hi i have a table defined with server side settings, and a custom ajax fn().
Before i call the ajax method to get the data from the server i need to intercept if the ordering has changed. I am doing this with the on.(order) as per the docs.
However the ajax call gets fired before the order call - i need to handle the order changed before i call the ajax method. Is there another way to handle this scenario??
window.onload = function () {
var pagingCookie = null;
var table = $('#example').DataTable({
processing: true,
serverSide: true,
pagingType: "full_numbers",
lengthMenu: [5, 10, 15],
ajax: function (data, callback, settings) {
// inject the 'many do records do we want' the fectxml the datatable page count
// before we call the server
},
columns: [
]
});
var iTableCounter = 0;
$('#example').on('length.dt', function (e, settings, len) {
// we need to clear down the paging cookie if we change the no. of requested for items
//
// This handler gets fired AFTER the table:ajax call, i need it before
//
pagingCookie = null;
});
$('#example').on('order.dt', function (e, settings, len) {
// we need to clear down the paging cookie if we change the order criteria
//
// This handler gets fired AFTER the table:ajax call, i need it before
//
pagingCookie = null;
});
};
This discussion has been closed.
Replies
The order event occurs after a draw (it should perhaps be called
postOrder
).So what you would need to do is inspect the
data
property in your Ajax data function to determine what the order is (it is in theorder
parameter).Allan
Is there a field in order "Data::Order" which will help me determine if the sort order has changed. I need to just know that the sort col has changed.
Obviously i can store this manually and compare.. just checking there is no field / flag that would let me know its changed