-1
I have a function that returns all customer registrations. But my question is how can I make a pagination with this code? THE ELEMENTS ARE CREATED DYNAMICALLY. HOW CAN I RESOLVE THIS?
function retorna_cliente ()
{
var id_cliente = "";
var nome_cliente = "";
var data_nascimento_cliente = "";
var telefone_cliente = "";
var celular_cliente = "";
var cpf_cliente = "";
var endereco_cliente = "";
var email_cliente = "";
var container_mostra_cliente = $('.mostra_clientes');
var itemHTML = "";
var mensagem_cliente = "Nenhum cliente encontrado";
$.ajax({
url: url_base + "clientes",
type: 'GET',
dataType: 'json',
success: function (data)
{
if (data == 0)
{
$('.cliente-error-registro').css('display','block');
$('.cliente-error-registro .mensagem-erro').html(mensagem_cliente);
}
else
{
itemHTML += "<table id='datatable-checkbox' class='table table-striped table-bordered bulk_action dataTable no-footer' role='grid' aria-describedby='datatable-checkbox_info'>";
itemHTML += "<thead>";
itemHTML += "<tr>";
itemHTML += "<th>";
itemHTML += "<th><input type='checkbox' id='check-all' class='flat'></th>";
itemHTML += "</th>";
itemHTML += "<th>Nome</th>";
itemHTML += "<th>Data de Nascimento</th>";
itemHTML += "<th>Telefone</th>";
itemHTML += "<th>Celular</th>";
itemHTML += "<th>Cpf</th>";
itemHTML += "<th>Endereço</th>";
itemHTML += "<th>Email</th>";
itemHTML += "</tr>";
itemHTML += "</thead>";
data.forEach(function (item)
{
id_cliente = item.id;
nome_cliente = item.nome;
data_nascimento_cliente = formataDataSQL(item.data_nascimento);
telefone_cliente = item.telefone;
celular_cliente = item.celular;
cpf_cliente = item.cpf;
endereco_cliente = item.endereco;
email_cliente = item.email;
itemHTML += "<tbody>";
itemHTML += "<tr>";
itemHTML += "<td><th><input type='checkbox' value='" + id_cliente + "' name='verifica_check_box[]' id='verifica_check_box' class='flat'/></th></td>";
itemHTML += "<td>" + nome_cliente + "</td>";
itemHTML += "<td>" + data_nascimento_cliente + "</td>";
itemHTML += "<td>" + telefone_cliente + "</td>";
itemHTML += "<td>" + celular_cliente + "</td>";
itemHTML += "<td>" + cpf_cliente + "</td>";
itemHTML += "<td>" + endereco_cliente + "</td>";
itemHTML += "<td>" + email_cliente + "</td>";
itemHTML += "</tr>";
itemHTML += "</tbody>";
});
itemHTML += "</table>";
container_mostra_cliente.append(itemHTML);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
console.log(data);
}
});
}
Possible duplicate of Paging with ajax
– David Alves
Possible duplicate of Paging with Jquery
– Felipe Duarte
Well I would like to know the logic how I could make this pagination because it creates the elements dynamically.
– Felipe Michael da Fonseca
You can send along with the ajax request a control variable indicating the start record of the Current list. For example starting with zero and limiting the query to 20 records. When you have the page advanced, you will send the search starting from 20... or if you prefer to use https://datatables.net/ that makes everything easier....
– Leo Nogueira