Is is possible to set ajax but not use it?

Is is possible to set ajax but not use it?

tacman1123tacman1123 Posts: 198Questions: 46Answers: 1

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

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    Answer ✓

    The serverSide option tells Datatables whether or not the server script is used for sorting, searching and paging. Meaning the server script is perfroming "Server Side Processing". Setting serverSide false doesn't mean the data can't be fetched from the server. In this case all the table data is loaded, via ajax if ajax is specified, in client side processing mode. See these examples.

    One option might be to set default settings with serverSide true and your ajax config. Then in the Datatables init code set serverSide false and ajax to null. 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 -option serverSideand-option ajax` are turned off.

    Kevin

  • tacman1123tacman1123 Posts: 198Questions: 46Answers: 1

    Thanks, Kevin, very helpful. I hadn't made the connection between the initial load and the subsequent sorting/searching. Makes more sense now.

Sign In or Register to comment.