Datatable create and populate table dynamically with server-side paging

Asked

Viewed 753 times

0

Personal how can I make a form submission, a Datatable is created and populated with the result of the filter made in the form and make Datatable do server-side paging.

Datatable Version: 1.9.4

The first part of creating Datatable and popular with the result is working like this:

var table = $('#exemplo').DataTable({
    processing: true,
    serverSide: true
});

$('#enviar').click(function(event) {
    var formData = $('form[name="form-teste"]').serialize();

    $.ajax({
        url: 'consulta.php',
        method: 'GET',
        data: formData + '&action=consulta',
        cache: false,
        dataType: 'json',
        beforeSend: function()
        {
            table.fnClearTable();
        }
    }).done(function(data)
    {
        table.fnAddData(data.data);

    }).fail(function(error)
    {
        console.log('error');
    });

});

JSON is like this:

{
    "draw":0,
    "recordsTotal":2,
    "recordsFiltered":2,
    "data":
        [
            [
                "teste 1",
                "3232132",
                "237",
                "123",
                "456",
                "joao",
                "1000.00",
                "300.00",
                "62079786768",
                null
            ],
            [
                "teste 2",
                "33323",
                "237",
                "123",
                "456",
                "joao",
                "1000.00",
                "300.00",
                "62079786768",
                null
            ]
        ]
}

Now the server-side paging part is that I can’t find a solution

  • Didn’t help at all @Edilson but Valew just like that man

  • It’s basically what you’re looking for. Enter the code you’re currently using for your query.

  • But this mine already does, I am looking now is a solution for server-side paging

  • But the pagination part is also there.

  • Hello. I also searched a lot and would like to know how to do it. However, I found an excellent solution in the link below. https://coderexample.com/datatable-scroller-server-side/ Best wishes.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.