1
I have the following each that returns all customer records within 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 like this: Like a pagination, each DIV will have to have 4 records. If there are 20 records in the table it via have to be broken into DIVS with 4 information each div, example:
Example: https://jsfiddle.net/khpo3k8m/2/
So it would be easier to make a pagination.
How to return datatable values? I’ve tried 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" }
]
} );
DATATABLE CODE WITH DESTROY. DOES NOT WORK:
function retorna_cliente()
{
var tabela = $('.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();
}
So how do you get him to return a json with the information? I’ve tried to see in the question edit
– Felipe Michael da Fonseca
I edited my answer to try to help you. Make sure that what is returned from your url_base is a type of date valid.
– Caique Romero
Yeah, it worked out. Only it returns the error: Datatables Warning: table id=datatable-checkbox - Requested Unknown Parameter '' for Row 0, column 1. For more information about this error, Psee lease http://datatables.net/tn/4
– Felipe Michael da Fonseca
And there is another error: Datatables Warning: table id=datatable-checkbox - Cannot reinitialise Datatable. For more information about this error, Please see http://datatables.net/tn/3
– Felipe Michael da Fonseca
If you load the data from it dynamically you need to include the parameter -> "bDestroy": true
– Caique Romero
I’ve tried everything guy. It even worked except that there is no show of total records. Before without Destroy he appeared
– Felipe Michael da Fonseca
https://datatables.net/reference/option/info gives a brief look at the options that datatables has > https://datatables.net/reference/option/
– Caique Romero
I edited the question see the code and image
– Felipe Michael da Fonseca
any error in the console?
– Caique Romero
Well there is another alternative that instead of Destroy would be to call the method again $('#example'). Datatable();
– Caique Romero
No. Nothing appears. It simply does not assemble the options
– Felipe Michael da Fonseca