I have the following each that returns all records of clients inside a table, and that works perfectly:
$.each(data, function(key,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.html(itemHTML);
}
Here it displays a normal table, but I wanted it to be this way: Like a paging, every DIV will have to have 4 records. If you have 20 records in the table it would have to be broken into DIVS with 4 information each div, eg
Example: link
This would make it easier to make a paging.
How to return the values from the datatable? I've tried it in ajax and nothing!
$('.mostra_clientes .table').DataTable( {
retrieve: true,
"processing": true,
paging: false,
searching: false,
"pageLength": 4,
"ajax": {
"type" : "GET",
"url" : url_base + "clientes",
},
"columns": [
{ "data": "nome" },
{ "data": "data_nascimento" },
{ "data": "telefone" },
{ "data": "celular" },
{ "data": "cpf" },
{ "data": "endereco" },
{ "data": "email" }
]
} );
DATABASECODEWITHDESTROY.DOESNOTWORK:
functionretorna_cliente(){vartabela=$('.mostra_clientes.table').DataTable({"pageLength": 4,
"bPaging": "false",
"bDestroy": "true",
"ajax": {
"url": url_base + "clientes",
"type": "GET",
"dataSrc": "",
},
"columns": [
{
"data": function ( data, type, row ) {
return "<input type='checkbox' value='"+data['id']+"' name='verifica_check_box[]' id='verifica_check_box' class='flat'/>";
}
},
{ "data":"nome"},
{ "data":"telefone"},
{ "data":"cpf"},
{ "data":"endereco"},
{ "data":"email"},
],
"bLengthChange": false,
"bInfo": false,
"bAutoWidth": false
});
tabela.destroy();
}