Jquery Datatable Paging

2

Is it possible to set the number of pages without having the records? I want a more efficient paging, load page data when the page is clicked.

The datatable it loads all the data creating the paging, and I have a client that loads 30 thousand records, this will leave slow to load the data.

    
asked by anonymous 26.02.2016 / 17:25

2 answers

3
  

Is it possible to set the number of pages without having the records?

No.

  

I want a more efficient paging, load page data when clicked on page.

That's what he already does. You just need to change the behavior of the Datatable.

  

The datatable it loads all the data creating the paging, and I have a client that loads 30 thousand records, this will leave slow to load the data.

Go. That's why you should use Datatables Ajax support to do this load more selectively.

For example:

<script>
    jQuery(document).ready(function () {
        var datatable = $('table').DataTable({
            order: [1, "asc"],
            processing: true,
            paging: true,
            serverSide: true,
            ajax: {
                url: '/Cidades/PesquisarAjax',
                type: 'POST'
            },
            columns: [
                {
                    "name": "Estado",
                    "title": "Estado",
                    "render": function (data, type, full, meta) {
                        return full.Estado.Nome;
                    }
                },
               { "name": "Nome", "data": "Nome", "title": "Nome" },
               { "name": "CodigoIbge", "data": "CodigoIbge", "title": "Código no IBGE" },
               { "name": "CodigoSiafi", "data": "CodigoSiafi", "title": "Código no SIAFI" }
            ],
        });

        datatable.columns().every(function () {
            var that = this;

            $('input', this.footer()).on('keyup change', function () {
                that
                    .search(this.value)
                    .draw();
            });
        });
    });
</script>

/Cidades/PesquisaAjax returns a JSON something like this:

{
    "draw": 0,
    "data": [ /* Aqui são objetos JSON cujos nomes de propriedades são as colunas da tela, e os valores são os valores das respectivas colunas */ ],
    "recordsFiltered": 100,
    "recordsTotal": 30000
}

See more here .

    
26.02.2016 / 17:37
0

I discovered how to do Rafael, On the server side you put together in the string, which will generate the json, this information, which ajax will capture on the client side.

$string["sEcho"] = 3;
$string["iTotalRecords"] = $rowCount;
$string["iTotalDisplayRecords"] = $rowCount;
echo json_encode($string);
    
26.08.2017 / 18:03