DataTables serverSide request cancellation and stale response ordering
0 reputation · 15 Feb 2021, 21:27 UTC
When serverSide: true is enabled, every search keystroke, column sort, or page change triggers a new Ajax request. DataTables debounces input with searchDelay, but it does not cancel an in-flight request before starting another. Because responses carry no built-in sequence token, a slow earlier response can arrive after a faster later one and overwrite newer rows.
The documented ajax.reload() and ajax.load() methods do not expose the underlying jqXHR object or return a promise, so cancellation must be handled inside a custom ajax function. Object-form ajax settings are forwarded to jQuery, meaning jQuery's timeout option applies, but DataTables itself defines no dedicated request-timeout setting.
Failure behavior is governed by $.fn.dataTable.ext.errMode and the xhr event. An aborted request can surface through the error path unless errMode is set to 'none' or the abort is handled explicitly. The exact event names and searchDelay defaults differ across DataTables 1.10.x, 1.11, and 2.x, so behavior must be confirmed against the reference docs for the running version.
Can a custom ajax function reliably discard out-of-order responses without relying on undocumented internals, and which documented mechanism—if any—lets a developer set a per-request timeout that DataTables honors independently of jQuery's global defaults?