lewis4u
lewis4u

Reputation: 15027

Datatable server side ajax on demand

How to setup server side processing and not to load the datatable right away but on a button?

With this setup:

var usersTable = $('#users').DataTable({
    responsive: true,
    processing: true,
    serverSide: true,
    autoWidth: false,
    ajax: 'https://example.com/users',
    ..............................

the datatable is loaded straight away and I want to load it on click

Is this possible somehow?

Upvotes: 0

Views: 108

Answers (1)

Python Hunter
Python Hunter

Reputation: 2146

How about:

<button id="my_button" value="click to load DB table!" />

<script>
$( document ).ready(function() {
    $('#my_button').click(function(){
        load_table();
    });

    function load_table() {
        var usersTable = $('#users').DataTable({
            responsive: true,
            processing: true,
            serverSide: true,
            autoWidth: false,
            ajax: 'https://example.com/users',
            ..............................
        });
    }
});
</script>

Upvotes: 1

Related Questions