How do I set the datatables not to send ajax requests when the page load

How do I set the datatables not to send ajax requests when the page load

LihengLiheng Posts: 1Questions: 1Answers: 0
edited June 2019 in Free community support

How do I set the datatables not to send ajax requests when the page loads, but to send ajax requests when I click on the query button

$(document).ready(function () {
                var table = $("#example").DataTable({
                    scrollX: true,
                    destroy: true,
                    columns: [
                        {data: "name"},
                        {data: "position"},
                        {data: "office"},
                        {data: "age"},
                        {data: "startdate"},
                        {data: "salary"}
                    ],
                    ajax: {
                        url: "user/findById",
                        data: function (d) {
                            d.id = $("#userId").val()
                        }
                    }
                });
             
               $("#queryUser").click(function () {
                    table.ajax.reload();
                });
}

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @leheng ,

    You can't really, as the table will try and get the data when first initialised. What you can do though, is just reinitalise the table, something like this,

    Cheers,

    Colin

This discussion has been closed.