Evaluating a new data object against the DataTables search algorithm
Evaluating a new data object against the DataTables search algorithm

I am incorporating websocket/STOMP update notifications to make our ajax based datatables more responsive.
As part of this effort, I would like to determine if an updated data object still matches the DataTables search specification (we are using column based search), and do an in-place replacement if the updated data still meets the search criteria (instead of calling draw and triggering an ajax call).
I prefer to just not call draw() for every update (it causes screen jitter and the drop down menus that we have in some column values get rebuilt so they disappear under the user's cursor. It's just not a great experience.
Instead of re-implementing the search logic, I'd ideally like to be able to re-use the DataTables implementation, is there a way to get at that? The key is that this is an ajax driver DT, we just have a few operations where we want to be more surgical than loading the entire table.
BTW, the update algorithm I'm using is as follows:
When we receive a STOMP update notice, it includes the record id that was changed. We loop the existing DataTable rows to see if any of them contain that id. If we find a matching row, we then do an ajax call to get only that record, then do a dtRow.data(newData).invalidate(); This causes only that row to be redrawn.
What I would like to do is detect if the newData no longer matches the search(), and if that happens, then visually mark the row (change the opacity or something) and start a 1500ms interruptible refresh timer. When the UI settles down, the timer will expire, and we would then trigger a draw() to get the updated version of the paged data (effectively removing the row). Same approach for deleted rows.
If this isn't possible, another idea I'm kicking around is to trigger the ajax call, but add an additional parameter for the id of interest (table.ajax.params() + '&id=123'). If that returns no records, then we would use the removal approach I describe above.
Any thoughts?
Answers
Unfortunately no, there isn't an option for that I'm afraid. I do see the utility in that, and possibly the ability to replace the default implementation, but at the moment you'd need to pull the logic out of DataTables and rework it.
This is the function you want if you did want to head down that road.
I will look at making it accessible in future.
Allan
Thanks. I ultimately decided to go with my "other option" - initiating my own ajax query against only the changed rows, then doing an in-place update. The result is super responsive, and the search syntax is completely consistent with the back-end.
Here's the implementation in case anyone else would benefit:
example usage:
This can then be used in an event handler (in my case, triggered by a websocket STOMP message that contains the list of ids that have changed).
I'm going to hold off on debouncing the draw() call as this isn't impacting our application much right now, but it would be pretty easy to implement.
Just realized that there is one line in this code that uses an external function dependency:
that will need to be adjusted for the specific ajax call approach.
Update that includes a default ajax handler (which can be overidden with the optional doAjaxCallFn config value):
Basic usage:
Complete configuration example:
That's awesome. Thanks for sharing your solution with us!
Allan