How to refresh the table without using json?
How to refresh the table without using json?
Hello all,
i am not using json to create my table.
i am just making a SELECT on the database and after that i call the html table with the data.
so my doubt is... i would like to refresh my table after an insert, because i need everytime to refresh my page to data appear.
i know how to do it with json, but it will be more fast and productive for me if i have a way to do it without using json!
var table = $('#table_id').DataTable({
"lengthMenu": [[15, 50, 100, 150, -1], [15, 50, 100, 150, "Todos"]],
"stateSave": true,//salva a posição da tabela(paginação ou consulta) ao dar refresh.
"language": {
"sProcessing": "A processar...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "Não foram encontrados resultados",
"sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
"sInfoEmpty": "Mostrando de 0 até 0 de 0 registros",
"sInfoFiltered": "(filtrado de _MAX_ registros no total)",
"sInfoPostFix": "",
"sSearch": "Procurar:",
"sUrl": "",
"oPaginate": {
"sFirst": "Primeiro",
"sPrevious": "Anterior",
"sNext": "Seguinte",
"sLast": "Último"
},
"buttons":{
"copy": "Cópiar",
"excel": "Excel",
"pdf": "PDF",
"print": "Imprimir",
"colvis": "Colunas Visíveis",
}
},
"processing": true,
"columns": [
{ width: "5%" },//SEL
{ width: "5%" },//ALT
{ width: "5%" },//DEL
{ width: "85%" },//DESCRIÇÃO
],
"createdRow": function ( row, data, index ) {
//AJUSTA ALINHAMENTO DOS DADOS NA TABELA
$('td', row).eq(0).addClass('p-1 text-left');//CHECKBOX
$('td', row).eq(1).addClass('p-1 text-left');//ALT
$('td', row).eq(2).addClass('p-1 text-left');//DEL
$('td', row).eq(3).addClass('p-1');//DESCRIÇÃO
}
});
So, this is the code of my table and i am not using json!
thank you all.
Answers
Are you inserting the row with Editor? Are how is the SQL making it's way into the table?
Colin
This is the HTML code of my table.
Inside of the HTML code i call a PHP function that write the rows of the table with a SELECT.
As you can see i draw the rows of the table with a while.
so i use like that and works perfectly and i would like to keep like that!
Are you inserting the row with Editor?
no, i am using the free version of datatable for a while.
I created a submit button that after fill all the form i just press it and serialize with javascript. After that i call a php class and insert on database.
After the inserssion i just need that the datatable refresh to show the new row/data
What I would to is insert the new row then fetch the row from the DB and return just that row to the client. In the ajax success you can then take the returned row and use
row.add()
to add it to the Datatable. This is essentially what the Editor would do.Kevin
This is my code that call the inserssion
i did like you said..
i save all the form data in variables and after i call a PHP insert file that make connection to a class and DB to insert in DB.
and the return of it i take on ajax success.
So, can i draw a row into my table with function row.add() without use ajax json?
Of course. You can use
row.add()
at any point. The purpose of the above set of steps is that the user will see exactly what was inserted into the DB. If you don't need that then simply just userow.add()
.Kevin