fnSort binds to "sort" event and to "filter" event?
fnSort binds to "sort" event and to "filter" event?
jitterska
Posts: 3Questions: 0Answers: 0
Hi Allan,
First I just want to commend you on your excellent work. Anyone who uses jQuery should use your wonderful tool as well. I'm attempting to hook a few javascript calls into some of the DataTable's events and have had a lot of success in doing so by using the "bind" functionality. However I'm running into trouble when I attempt to separate the "sort" event from the "filter" event. I need two separate functions to occur, but when I sort my table, it also always calls the "filter" event. Any light you could shed on this would be extremely helpful. Thanks!
[code]
var oTable = $("#example").dataTable({
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaData": eval(response.d) }).bind("sort", function() { alert('sort called'); }).bind("filter", function() { alert('filter called'); });
oTable.fnSort([[4, 'desc']]);
[/code]
First I just want to commend you on your excellent work. Anyone who uses jQuery should use your wonderful tool as well. I'm attempting to hook a few javascript calls into some of the DataTable's events and have had a lot of success in doing so by using the "bind" functionality. However I'm running into trouble when I attempt to separate the "sort" event from the "filter" event. I need two separate functions to occur, but when I sort my table, it also always calls the "filter" event. Any light you could shed on this would be extremely helpful. Thanks!
[code]
var oTable = $("#example").dataTable({
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaData": eval(response.d) }).bind("sort", function() { alert('sort called'); }).bind("filter", function() { alert('filter called'); });
oTable.fnSort([[4, 'desc']]);
[/code]
This discussion has been closed.
Replies
The plan ( http://datatables.net/development/roadmap ) is to separate that behaviour - v1.11 and stop this from happening, but that's a good while off since 1.10 development hasn't even started yet...
I'm actually not 100% sure how to combat this at the moment. All I can say is that if the bFiltered and bSorted flags in the settings object ( http://datatables.net/docs/DataTables/1.9.1/DataTable.models.oSettings.html#bFiltered ) are both set, then its a sort that has happened.
A bit pants I know - but unfortunately fixing it is going to take a good deal of time.
Allan
for filtering, find the input box and attach a keyup event, delaying execution of the desired function by a certain time to allow people to enter a whole phrase without triggering it at every key stroke.
[code]
var keyTimer;
$("#tableDiv").find('input').keyup(function() {
clearTimeout(keyTimer);
keyTimer = setTimeout(function(){ console.log("filtered"); }, 500);
});
[/code]
similar for sorting, just attach a click handler to thead:
[code]
$("#tableDiv").find('thead').click(function() {
console.log("sorted");
});
[/code]
p.s.: also want to thank you Allan for the great job and effort! much appreciated! will insist my company donates something when the project is done.