This commit is contained in:
KONE SOREL 2026-01-19 17:23:55 +00:00
parent b22846229c
commit 4b1529360e
4 changed files with 60 additions and 50 deletions

View File

@ -41,6 +41,7 @@ function connexion_cookie()
$(function() { $(function() {
// Initialisation des composants au chargement de la page // Initialisation des composants au chargement de la page
appliquerDataTable('.tabliste'); appliquerDataTable('.tabliste');
dataTableMini();
//const vueOuverte = $("#vue").val(); //const vueOuverte = $("#vue").val();
let nomForm = $("#nomForm").val(); let nomForm = $("#nomForm").val();
@ -1448,53 +1449,69 @@ function enregistrer_avenant()
} }
/** function dataTableMini() {
* Initialise un DataTable de manière générique avec support Ajax et Bootstrap const $table = $('.tabmini');
* @param {string} selector - L'ID ou la classe du tableau (ex: '#monTableau') const codeLangue = $("#codeLangue").val() || "fr_FR";
* @param {Object} customOptions - Options spécifiques pour surcharger la config par défaut
*/
function genericInitDataTable(selector, customOptions = {}) {
// 1. Sécurité : Vérifier si l'élément existe
if ($(selector).length === 0) return;
// 2. Si une instance existe déjà, on la détruit proprement // Détruire l'instance existante si elle existe
if ($.fn.DataTable.isDataTable(selector)) { if ($.fn.DataTable.isDataTable($table)) {
$(selector).DataTable().destroy(); $table.DataTable().clear().destroy();
$(selector).empty(); // Optionnel : vide le DOM si nécessaire
} }
// 3. Configuration par défaut (Standard pour votre portail RH) // Définition des traductions
const defaultOptions = { const langOptions = {
"language": { en_US: {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/fr-FR.json" lengthMenu: "Display _MENU_ records per page",
}, zeroRecords: "Nothing found - sorry",
"pageLength": 10, info: "Showing page _PAGE_ of _PAGES_",
"responsive": true, infoEmpty: "No records available",
"dom": '<"d-flex justify-content-between align-items-center mb-3"fB>rt<"d-flex justify-content-between align-items-center mt-3"ip>', search: "Search:",
"buttons": [ paginate: {
{ next: "►",
extend: 'excelHtml5', previous: "◄",
className: 'btn btn-sm btn-outline-success rounded-pill px-3', first: "|◄",
text: '<i class="far fa-file-excel me-1"></i> Excel' last: "►|"
}, },
{ infoFiltered: "(filtered from _MAX_ total records)"
extend: 'pdfHtml5', },
className: 'btn btn-sm btn-outline-danger rounded-pill px-3', fr_FR: {
text: '<i class="far fa-file-pdf me-1"></i> PDF' lengthMenu: "Affiche _MENU_ par page",
} zeroRecords: "Désolé - Aucune donnée trouvée",
], info: "_PAGE_ sur _PAGES_ pages",
"drawCallback": function() { infoEmpty: "Pas d'enregistrement",
// Style Bootstrap pour le champ de recherche search: "Recherche:",
$('.dataTables_filter input').addClass('form-control form-control-sm shadow-none rounded-pill'); paginate: {
$('.dataTables_paginate .paginate_button').addClass('btn btn-xs'); next: "►",
previous: "◄",
first: "|◄",
last: "►|"
},
infoFiltered: "(filtré de _MAX_ total enregistrements)"
} }
}; };
// 4. Fusion des options par défaut avec les options personnalisées try {
const finalOptions = $.extend(true, {}, defaultOptions, customOptions); $table.DataTable({
destroy: true,
responsive: true,
lengthMenu: [10], // tu peux mettre [10, 25, 50] pour plus de flexibilité
scrollX: true,
scrollY: "20vh",
pagingType: "full_numbers",
autoWidth: false,
searching: false, // équivalent moderne de bFilter:false
lengthChange: false, // équivalent moderne de bLengthChange:false
orderMulti: true,
language: langOptions[codeLangue] || langOptions.fr_FR
});
// 5. Initialisation // Ajuster les colonnes après init
return $(selector).DataTable(finalOptions); $table.DataTable().columns.adjust().draw();
} catch (err) {
console.error("Erreur DataTable:", err);
return false;
}
} }
@ -1529,14 +1546,7 @@ function pop_afficher_selection_retrait() {
div_selection_assure.html(data); div_selection_assure.html(data);
// 3. INITIALISATION DU DATATABLE GÉNÉRIQUE // 3. INITIALISATION DU DATATABLE GÉNÉRIQUE
// On cible l'ID du tableau qui est généré dans votre vue Ajax dataTableMini();
genericInitDataTable('#table_retrait_assures', {
"order": [[1, "asc"]], // Trie par nom
"pageLength": 10,
"columnDefs": [
{ "orderable": false, "targets": [-1] } // Désactive le tri sur la dernière colonne (Action)
]
});
}, },
complete: function() { complete: function() {
// 4. Gestion propre du Modal // 4. Gestion propre du Modal

View File

@ -70,7 +70,7 @@
<div class="card shadow-sm border-0"> <div class="card shadow-sm border-0">
<div class="table-responsive py-2"> <div class="table-responsive py-2">
<table id="table_retrait_assures" class="table table-hover align-middle border shadow-sm" style="width:100%; font-size: 8.5pt;"> <table class="table table-hover align-middle border shadow-sm tabmini compact" style="width:100%; font-size: 8.5pt;">
<thead class="table-dark"> <thead class="table-dark">
<tr class="text-center text-nowrap"> <tr class="text-center text-nowrap">
<th><?= _("Cat") ?></th> <th><?= _("Cat") ?></th>

View File

@ -3,7 +3,7 @@
?> ?>
<div class="table-responsive"> <div class="table-responsive">
<table id="table_retrait_assures" class="table table-striped table-hover align-middle border" style="width:100%; font-size:8pt;"> <table id="table_retrait_assures" class="table table-striped table-hover align-middle border tabmini compact" style="width:100%; font-size:8pt;">
<thead class="table-dark text-nowrap"> <thead class="table-dark text-nowrap">
<tr> <tr>
<th class="text-center small"><?= _("Cat") ?></th> <th class="text-center small"><?= _("Cat") ?></th>

View File

@ -654,7 +654,7 @@ $photoAssureCrypte = $_SESSION['photoAssureCrypte'];
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Application Scripts --> <!-- Application Scripts -->
<script src="/Js/fonctions.js?ver=2026.01.19.12"></script> <script src="/Js/fonctions.js?ver=2026.01.19.13"></script>
<script type="text/javascript"> <script type="text/javascript">
raffraichier_gabarit(); raffraichier_gabarit();