jhyland87 / DataTables-Live-Ajax

Keep an AJAX sourced DataTable up to date, without reloading the entire table at once (with custom interval and pausing ability)
http://www.linuxdigest.org/misc/script_examples/DataTables-Live-Ajax/examples/
MIT License
18 stars 8 forks source link

Feature: update changes from a table diff #3

Open petri opened 8 years ago

petri commented 8 years ago

For another purpose, I just implemented a server-side mechanism to return a list of changes that have been made to a (table-like) data source since last request. It's fairly simple, one just has to keep a timestamp on server side to identify subsequent requests (keyed by for example custom HTTP request header, GET/POST parameter, or URL path segment).

It's easy to see that for large tables, it can be very effective to be able to parse and update the datatable from this 'diff' (instead of reloading the full data each time). Especially in a scenario when data is read often but updated realtively rarely, and one can keep a change journal on server side that's modified whenever data is changed (rather than a diff being computed for each request).

A table diff could be as simple as a JSON array containing records comprised of just a operation indicator and (added/deleted/changed) row contents. Operation indicators could be numbers, such as -1 for deletion, 0 for change and 1 for addition. Or symbols such as '+', '-' and '~' . I would not recommend using full verbs such as "add", "delete" & "change", although it does not of course matter that much if the set of changes is always fairly small between requests.