as I showed you in the photo I would like to create those two tables which are now only in html, with the datatables editor, because then I have to add the sum in the footer and a control that when a data is inserted in the column in the main table "Autista Linea "the data in the two tables above must change
The Cannot reinitialise DataTable error you are getting is due to initializing the same table multiple times. You are using $('#scrivania1').DataTable( { ... } ); for 3 different tables. scrivania1 is the 'id' of your main table. What are the id's of the other two tables? You need to change the selector ( '#scrivania1' ) to the id of the table you want initialized.
The id selector has nothing to do with the data retrieved from the server. The id is a unique identifier for HTML elements like table. For your main table you have something like <table id="scrivania1" ....></table>. For your other two tables assign unique id's to them, for example, <table id="scrivania2" ....></table> and use those to assign the Datatable instance, for example $('#scrivania2').DataTable( { ... } );.
Answers
This example shows how to apply Datatables to a DOM based table.
Kevin
Maybe I was wrong to express myself, those two html tables are connected to the db of the table below, how can I make those tables datatables too?
I leave an example:
What do you want to do with the tables? It looks like they are already Datatables. Are you trying to insert them into the main table?
Kevin
as I showed you in the photo I would like to create those two tables which are now only in html, with the datatables editor, because then I have to add the sum in the footer and a control that when a data is inserted in the column in the main table "Autista Linea "the data in the two tables above must change
In a nutshell, those two tables are a sort of only visual control panel, to see the sum of the "Epal, Ind" columns grouped by the "scarico" column.
The query that those tables use is as follows:
SELECT scarico, sum(epal + perd), sum(ind) From scrivania1 where dlinea = '' and scarico !='' GROUP BY scarico
And
SELECT scarico_m, sum(epal + perd), sum(ind) From scrivania1 where dlinea = '' and scarico_m !='' GROUP BY scarico_m
(function($){
$(document).ready(function() {
$.fn.dataTable.moment('DD/MM/YYYY');
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.scrivania1.php',
table: '#scrivania1',
],
i18n: {
create: {
button: "Nuova Spedizione",
title: "Inserisci una nuova spedizione",
submit: "Conferma",
},
edit: {
button: "Modifica Spedizione",
title: "Modifica Spedizione",
submit: "Conferma"
},
remove: {
button: "Elimina Spedizione",
title: "Elimina Spedizione",
submit: "Elimina",
confirm: {
_: "Sei sicuro di voler eliminare %d riga?",
1: "Sei sicuro di voler eliminare questa riga?"
}
},
error: {
system: "Errore di sistema, contattare lo sviluppatore"
},
datetime: {
previous: 'Precedente',
next: 'Successivo',
months: [ 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ],
weekdays: [ 'Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab' ]
}
}
} );
searchPanes:{
columns:[5,7]
},
// select: true,
// lengthChange: true,
lengthMenu: [
[10, 20, 25, 50, -1],
[10 , 20, 25, 50, 'Tutte']
],
buttons: [
columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ,
modifier: {
page: 'current'
}
}
},
{extend: 'pageLength', editor: editor, text:'Mostra righe'}
}
table.draw(false);
});
} );
} );
var table = $('#scrivania1').DataTable( {
// serverSide: 'true',
dom: 'Bfrtip',
// dom: 'Pfrtip',
ajax: 'php/table.scrivania1.php',
columns:[
{
"data": "scarico_m"
},
{
"data": "epal"
},
{
"data": "ind"
}
],
} );
} );
}(jQuery));
I try this way but return me error tn/3 and idk how to remove it i really dont understand..
The
Cannot reinitialise DataTable
error you are getting is due to initializing the same table multiple times. You are using$('#scrivania1').DataTable( { ... } );
for 3 different tables.scrivania1
is the 'id' of your maintable
. What are theid
's of the other two tables? You need to change the selector ( '#scrivania1' ) to the id of thetable
you want initialized.Kevin
Kevin but i cant change the selector the 3 tables must pick the same data in the same db
The
id
selector has nothing to do with the data retrieved from the server. Theid
is a unique identifier for HTML elements liketable
. For your main table you have something like<table id="scrivania1" ....></table>
. For your other two tables assign uniqueid
's to them, for example,<table id="scrivania2" ....></table>
and use those to assign the Datatable instance, for example$('#scrivania2').DataTable( { ... } );
.Read more about the
id
attribute here.Kevin
i think "#scrivania1" was for db..ehm sorry man, just try ur way
@kthorngren yeees work, now how do this query in the table?
SELECT scarico, sum(epal + perd), sum(ind) From scrivania1 where dlinea = '' and scarico !='' GROUP BY scarico
Code table:
$('#scrivania2').DataTable( {
// serverSide: 'true',
// dom: 'Bfrtip',
// dom: 'Pfrtip',
ajax: 'php/table.scrivania1.php',
columns:[
{
"data": "scarico"
},
{
"data": "epal"
},
{
"data": "ind"
}
],
} );