Datatable Jquery Paging

Asked

Viewed 2,752 times

2

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

The datatable it loads all the data creating the pagination, and I have a client that carries 30,000 records, this will slow to load the data.

2 answers

3


There is the possibility to set the number of pages without having the records?

Not.

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

It’s what it already does. You just need to change Datatable’s behavior.

The datatable it loads all the data creating the pagination, and I have a client that carries 30,000 records, this will slow to load the data.

Go. That’s why you should use Ajax support from Datatables 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.

  • Gypsy, my problem is with the Sql Server part of doing 30,000 records, I have a query that pages those records, but next to the datatable, I had to upload 20 records initially, and when click on the page I make the query and bring the other 20 records of the page clicked.

  • So improve your question or ask another.

0

I figured out how to do Rafael, On the server side Voce puts together the string, which will generate the json, this information, which the ajax will capture on the client side.

$string["sEcho"] = 3;
$string["iTotalRecords"] = $rowCount;
$string["iTotalDisplayRecords"] = $rowCount;
echo json_encode($string);

Browser other questions tagged

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