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.
– Rafael
So improve your question or ask another.
– Leonel Sanches da Silva