Is is possible to set ajax but not use it?
Is is possible to set ajax but not use it?
I'm working on a general purpose library where the developer can optionally use ajax to load the table data. If serverSide is false, I'd like to use the html data, if it's set I'd like to load it from the ajax call, but it appears that ajax is always called.
My datatable configuration is
let setup = {
ajax: (params, callback, settings) => { console.error('calling ajax');},
serverSide: false
(...)
}
let dt = new DataTables(el, setup);
https://jsfiddle.net/tacman1123/co7j3gxa/2/
It appears that the ajax call is made even if serverSide is set to false.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
serverSideoption tells Datatables whether or not the server script is used for sorting, searching and paging. Meaning the server script is perfroming "Server Side Processing". SettingserverSidefalse doesn't mean the data can't be fetched from the server. In this case all the table data is loaded, via ajax ifajaxis specified, in client side processing mode. See these examples.One option might be to set default settings with
serverSidetrue and yourajaxconfig. Then in the Datatables init code setserverSidefalse andajaxtonull. See this example:https://live.datatables.net/wupirewo/1/edit
When you first run it the default options will be used with data fetched via ajax. Uncomment the Datatables init code and the HTML data is used because both
-optionserverSideand-option ajax` are turned off.Kevin
Thanks, Kevin, very helpful. I hadn't made the connection between the initial load and the subsequent sorting/searching. Makes more sense now.