Load data with AJAX, but not on initializing table.

Load data with AJAX, but not on initializing table.

postitiefpostitief Posts: 22Questions: 9Answers: 0

I have a datatable where data should be loaded with AJAX. But the data should not be loaded when the table is initialized. When a specific event is happening (eg button click), the data must be loaded by AJAX.

With

$('#table').DataTable().draw();

I can get the data in the table.

But how to prevent the data to be loaded directly on init (page load)?

$('#table').DataTable({
    serverSide: false,
    ajax: { url: '/path/to/data'},
    columns: [
        {data: 'id', name: 'p.id'},
        // ...
    ]
});

This question has an accepted answers - jump to answer

Answers

  • postitiefpostitief Posts: 22Questions: 9Answers: 0

    So what I basically need is deferLoading but with serverSide on false

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    You could do something like this - set the URL later and just load the data then.

    Colin

  • postitiefpostitief Posts: 22Questions: 9Answers: 0

    Sweet! That did the job! Tnx!

This discussion has been closed.