DataTable create and populate table dynamically with server-side pagination

0

Personal how can I make when submitting a form, a DataTable is created and populated with the result of the filter done in the form and have DataTable do server-side paging.

DataTable Version: 1.9.4

The first part of creating the 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 looks 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 part of server-side pagination is that I can not find a solution

    
asked by anonymous 13.11.2015 / 20:30

0 answers