scrollToRow callbacks with ajax
scrollToRow callbacks with ajax
I've got a data table that uses server side processing and the scroller extension.
I've got a piece of javascript that scrolls to a specific row in the table, and then I want to highlight it. At the moment, I've put the highlight code in the table's draw
callback, so it happens after the new data has been downloaded and the table has been redrawn.
The problem is, if I only scroll by a row two, then no new data needs to be loaded and the draw
callback is never called - in this case I don't get my highlight.
Is there a good way to get round this problem? The workaround I have in mind is to somehow find out whether my target row is already loaded. If it is, then I call the highlight myself, and if it isn't I leave it to the draw
callback to take care of it. Or can I force the table to redraw and thus invoke the highlight? Or is there a better idea?
Thanks,
Steve.
Answers
I've just seen this buried in the documentation:
"Note that as of DataTables 1.10.6 the xhr event will be triggered when a function is used for ajax (even if there is no Ajax request). Prior to 1.10.6 no event would have been triggered."
I suspect this might be what I'm looking for. I can't test it right now, but I'll report back when I've tried it.
So the xhr event isn't what I'm looking for - it's not triggered if there's no ajax call to load more data. The search continues...
The only way I've been able to handle this is with a two-pronged approach.
First, I attached a listener to the scrollable table area:
This handles the case for short scrolls, when no extra data is loaded from the server. For the server case, I have the following in my table declaration:
ajax
property, we remove the timeout from the short scroll handler above, since we're getting more data and need to delay the highlight until it's retrieveddrawCallback
property, which is triggered once the data has been downloaded and the table is updated.This seem to be the best approach for the question. I'm open to alternatives though.