Skip to content

Commit d9b022a

Browse files
committed
fix: inizializzazione tabelle
1 parent 205d2d1 commit d9b022a

7 files changed

Lines changed: 32 additions & 8 deletions

File tree

assets/src/js/base/custom.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ $(document).ready(function () {
6969
// Avvio datatables dei plugin solo al primo click
7070
$('.nav-tabs li').not('.clicked').on('click', function(){
7171
$(this).addClass('clicked');
72-
start_datatables( $(".tab-pane.active .main-records-plugins") );
72+
// Inizializza solo le tabelle dei plugin che non sono già state inizializzate
73+
// Usa un timeout per assicurarsi che il tab sia completamente attivo
74+
setTimeout(function() {
75+
start_datatables( $(".tab-pane.active .main-records-plugins") );
76+
}, 100);
7377
});
7478

7579
// Calendario principale

assets/src/js/functions/datatables.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ function start_local_datatables() {
3535

3636
// Datatable
3737
function start_datatables( $elements ) {
38-
start_local_datatables();
38+
// Inizializza le tabelle locali solo se ce ne sono di non inizializzate
39+
let uninitializedLocalTables = $('.datatables').filter(function() {
40+
return !$.fn.DataTable.isDataTable($(this));
41+
});
42+
43+
if (uninitializedLocalTables.length > 0) {
44+
start_local_datatables();
45+
}
3946

4047
$elements.each(function () {
4148
const $this = $(this);
@@ -104,6 +111,7 @@ function start_datatables( $elements ) {
104111
url: "ajax_dataload.php?id_module=" + id_module + "&id_plugin=" + id_plugin + "&id_parent=" + id_parent,
105112
type: 'GET',
106113
dataSrc: "data",
114+
107115
},
108116
initComplete: initComplete,
109117
drawCallback: drawCallback,
@@ -317,7 +325,6 @@ function initComplete(settings) {
317325
var table = wrapper.datatable;
318326
var row_ids = wrapper.getSelectedRows();
319327
wrapper.removeSelectedRows(row_ids);
320-
table.clear().draw();
321328

322329
setTableSearch(module_id, field, search_value);
323330
column.search(search_value).draw();
@@ -460,7 +467,10 @@ function getTable(selector) {
460467

461468
initDatatable: function () {
462469
if (table.hasClass('datatables')) {
463-
start_local_datatables();
470+
// Inizializza solo se non è già stata inizializzata
471+
if (!$.fn.DataTable.isDataTable(table)) {
472+
start_local_datatables();
473+
}
464474
} else {
465475
start_datatables( $('.main-records') );
466476
}

plugins/importFE/edit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ function searchInvoices(btn) {
262262
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
263263
buttonRestore(btn, restore);
264264
265+
// Reinizializza le tabelle DataTables dopo il caricamento dinamico
266+
start_local_datatables();
267+
265268
// Applica il filtro di ricerca se presente
266269
applySearchFilter();
267270

plugins/importFE/list.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ function process_fe(button, file) {
187187
},
188188
success: function(data) {
189189
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
190+
// Reinizializza le tabelle DataTables dopo il caricamento dinamico
191+
start_local_datatables();
190192
buttonRestore(button, restore);
191193
});
192194
}
@@ -215,6 +217,8 @@ function delete_fe(button, file_id) {
215217
},
216218
success: function(data) {
217219
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
220+
// Reinizializza le tabelle DataTables dopo il caricamento dinamico
221+
start_local_datatables();
218222
buttonRestore(button, restore);
219223
});
220224
}
@@ -231,6 +235,5 @@ function download_fe(button, file_id) {
231235
}, "get", true);
232236
}
233237
234-
start_local_datatables();
235238
init();
236239
</script>';

plugins/importFE_ZIP/list.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,5 @@ function download_fe_vendita(button, file_id) {
296296
}, "get", true);
297297
}
298298
299-
start_local_datatables();
300299
init();
301300
</script>';

plugins/receiptFE/edit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ function searchReceipts(button) {
248248
$("#list-receiptfe").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'&refresh_cache=" + Date.now(), function() {
249249
buttonRestore(button, restore);
250250
251+
// Reinizializza le tabelle DataTables dopo il caricamento dinamico
252+
start_local_datatables();
253+
251254
// Applica il filtro di ricerca se presente
252255
applySearchFilter();
253256

plugins/receiptFE/list.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ function import_fe(button, file) {
107107
importMessage(data);
108108
109109
buttonRestore(button, restore);
110-
$("#list-receiptfe").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'");
110+
$("#list-receiptfe").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
111+
// Reinizializza le tabelle DataTables dopo il caricamento dinamico
112+
start_local_datatables();
113+
});
111114
},
112115
error: function(xhr) {
113116
$("#main_loading").fadeOut();
@@ -196,5 +199,4 @@ function process_fe(button, file) {
196199
});
197200
}
198201
199-
start_local_datatables();
200202
</script>';

0 commit comments

Comments
 (0)