Inizializzazione datatables nei plugin solo quando vengono aperti

This commit is contained in:
loviuz 2023-05-20 01:19:26 +02:00
parent 9b583a7259
commit cb94c91a86
3 changed files with 11 additions and 5 deletions

View File

@ -74,7 +74,13 @@ $(document).ready(function () {
numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali));
// Richiamo alla generazione di Datatables
start_datatables();
start_datatables( $('.main-records') );
// Avvio datatables dei plugin solo al primo click
$('.nav-tabs li').not('.clicked').on('click', function(){
$(this).addClass('clicked');
start_datatables( $(".tab-pane.active .main-records-plugins") );
});
// Calendario principale
start_complete_calendar("#daterange", function (start, end) {

View File

@ -34,10 +34,10 @@ function start_local_datatables() {
}
// Datatable
function start_datatables() {
function start_datatables( $elements ) {
start_local_datatables();
$('.main-records').each(function () {
$elements.each(function () {
const $this = $(this);
// Controlla che la tabella non sia già inizializzata
@ -451,7 +451,7 @@ function getTable(selector) {
if (table.hasClass('datatables')) {
start_local_datatables();
} else {
start_datatables();
start_datatables( $('.main-records') );
}
},
datatable: table.DataTable(),

View File

@ -99,7 +99,7 @@ if (!empty($type) && $type != 'menu' && $type != 'custom') {
$table_id = 'main_'.rand(0, 99);
echo '
<table data-idmodule="'.$id_module.'" data-idplugin="'.$id_plugin.'" data-idparent="'.$id_record.'" data-selected="'.implode(';', $selezione).'" id="'.$table_id.'" width="100%" class="main-records table table-condensed table-bordered">
<table data-idmodule="'.$id_module.'" data-idplugin="'.$id_plugin.'" data-idparent="'.$id_record.'" data-selected="'.implode(';', $selezione).'" id="'.$table_id.'" width="100%" class="main-records'.(!empty($id_plugin) ? '-plugins' : '').' table table-condensed table-bordered">
<thead>
<tr>
<th id="th_selector"></th>';