diff --git a/Js/fonctions.js b/Js/fonctions.js index d906132b..87fdf78d 100755 --- a/Js/fonctions.js +++ b/Js/fonctions.js @@ -92140,24 +92140,32 @@ function enregistrer_modif_parametres_med() } -function initSmartTable(selector = '.datatable-inter', pageTitle = 'Export Données') { +/** + * Initialise DataTables avec options d'export et de tri + * @param {string} selector - Sélecteur CSS de la table + * @param {string} pageTitle - Titre pour les exports PDF/Excel + * @param {boolean|array} defaultOrder - Exemple: [1, 'desc'] ou false pour garder l'ordre serveur + */ +function initSmartTable(selector = '.datatable-inter', pageTitle = 'Export Données', defaultOrder = false) { if ($(selector).length === 0) return; - // Détection automatique : la barre de recherche personnalisée existe-t-elle ? var hasGlobalSearch = $('#globalSearch').length > 0; if ($.fn.DataTable.isDataTable(selector)) { $(selector).DataTable().destroy(); } - // Configuration du DOM : - // Si hasGlobalSearch est vrai, on retire 'f' (recherche native) var domStructure = hasGlobalSearch ? '<"d-flex align-items-center justify-content-start p-3 border-bottom"B>t<"d-flex justify-content-between align-items-center p-3 bg-light"ip>' : '<"d-flex align-items-center justify-content-between p-3 border-bottom"Bf>t<"d-flex justify-content-between align-items-center p-3 bg-light"ip>'; + // Détermination de l'option "order" : + // Si defaultOrder est explicitement false, on passe un tableau vide pour désactiver le tri auto + var orderConfig = (defaultOrder === false) ? [] : defaultOrder; + var table = $(selector).DataTable({ "dom": domStructure, + "order": orderConfig, // <--- AJOUT ICI "buttons": [ { extend: 'excelHtml5', @@ -92181,7 +92189,6 @@ function initSmartTable(selector = '.datatable-inter', pageTitle = 'Export Donn "pageLength": 10, "autoWidth": false, "drawCallback": function() { - // Style uniquement si la recherche native est affichée if (!hasGlobalSearch) { $('.dataTables_filter input').addClass('form-control form-control-sm d-inline-block ms-2 rounded-pill border-2 shadow-none').css('width', '200px'); } @@ -92189,7 +92196,6 @@ function initSmartTable(selector = '.datatable-inter', pageTitle = 'Export Donn } }); - // LIAISON AUTOMATIQUE : Si globalSearch existe, on branche l'événement tout de suite if (hasGlobalSearch) { $('#globalSearch').off('keyup').on('keyup', function() { table.search(this.value).draw(); diff --git a/Vue/Parambons/index.php b/Vue/Parambons/index.php index 47302a98..8d85bba1 100755 --- a/Vue/Parambons/index.php +++ b/Vue/Parambons/index.php @@ -73,7 +73,7 @@ window.addEventListener('load', function() { if (typeof jQuery !== 'undefined') { // La fonction détecte seule #globalSearch et lie la recherche ! - initSmartTable('.table', 'Gestion des Bons'); + initSmartTable('.table', 'Gestion des Bons', false); } });