dsaer
This commit is contained in:
parent
063e3b072d
commit
aba92b07f2
|
|
@ -367,10 +367,8 @@ function changer_langue_connexion() {
|
||||||
* @param {string} message - Informations de police/contexte sous le titre (messageTop)
|
* @param {string} message - Informations de police/contexte sous le titre (messageTop)
|
||||||
*/
|
*/
|
||||||
function appliquerDataTable(selector = '.tabliste', options = {}, titreDoc = "Rapport", message = "") {
|
function appliquerDataTable(selector = '.tabliste', options = {}, titreDoc = "Rapport", message = "") {
|
||||||
// 1. Détection de la langue via un champ caché dans votre header
|
|
||||||
const codeLangue = $("#codeLangue").val() || 'fr_FR';
|
const codeLangue = $("#codeLangue").val() || 'fr_FR';
|
||||||
|
|
||||||
// 2. Dictionnaire de traduction
|
|
||||||
const translations = {
|
const translations = {
|
||||||
fr_FR: {
|
fr_FR: {
|
||||||
lengthMenu: "Affiche _MENU_ par page",
|
lengthMenu: "Affiche _MENU_ par page",
|
||||||
|
|
@ -379,10 +377,7 @@ function appliquerDataTable(selector = '.tabliste', options = {}, titreDoc = "Ra
|
||||||
infoEmpty: "Aucun enregistrement disponible",
|
infoEmpty: "Aucun enregistrement disponible",
|
||||||
infoFiltered: "(filtré de _MAX_ total)",
|
infoFiltered: "(filtré de _MAX_ total)",
|
||||||
search: "Recherche rapide :",
|
search: "Recherche rapide :",
|
||||||
paginate: {
|
paginate: { next: "Suivant ►", previous: "◄ Précédent" }
|
||||||
next: "Suivant ►",
|
|
||||||
previous: "◄ Précédent"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
en_US: {
|
en_US: {
|
||||||
lengthMenu: "Display _MENU_ records",
|
lengthMenu: "Display _MENU_ records",
|
||||||
|
|
@ -391,63 +386,53 @@ function appliquerDataTable(selector = '.tabliste', options = {}, titreDoc = "Ra
|
||||||
infoEmpty: "No records available",
|
infoEmpty: "No records available",
|
||||||
infoFiltered: "(filtered from _MAX_ total)",
|
infoFiltered: "(filtered from _MAX_ total)",
|
||||||
search: "Quick Search:",
|
search: "Quick Search:",
|
||||||
paginate: {
|
paginate: { next: "Next ►", previous: "◄ Previous" }
|
||||||
next: "Next ►",
|
|
||||||
previous: "◄ Previous"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(selector).each(function() {
|
$(selector).each(function() {
|
||||||
const $table = $(this);
|
const $table = $(this);
|
||||||
|
|
||||||
// 3. Gestion automatique des colonnes masquées (via l'attribut data-hidden="true" sur le TH)
|
|
||||||
const hiddenTargets = [];
|
const hiddenTargets = [];
|
||||||
$table.find('thead th').each((idx, th) => {
|
$table.find('thead th').each((idx, th) => {
|
||||||
if ($(th).data('hidden')) {
|
if ($(th).data('hidden')) hiddenTargets.push(idx);
|
||||||
hiddenTargets.push(idx);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. Configuration des boutons d'export avec Titre et Message Contextuel
|
|
||||||
const exportConfig = {
|
const exportConfig = {
|
||||||
title: titreDoc,
|
title: titreDoc,
|
||||||
messageTop: message,
|
messageTop: message,
|
||||||
exportOptions: {
|
exportOptions: { columns: ':visible' }
|
||||||
columns: ':visible' // Exporte uniquement ce qui est affiché à l'écran
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 5. Initialisation de l'instance DataTable
|
// --- CORRECTION ICI ---
|
||||||
|
// On définit les boutons par défaut uniquement SI aucun bouton n'est fourni dans 'options'
|
||||||
|
const defaultButtons = [
|
||||||
|
$.extend(true, {}, exportConfig, { extend: 'copy', className: 'btn btn-sm btn-light' }),
|
||||||
|
$.extend(true, {}, exportConfig, { extend: 'excel', className: 'btn btn-sm btn-success' }),
|
||||||
|
$.extend(true, {}, exportConfig, {
|
||||||
|
extend: 'pdf',
|
||||||
|
className: 'btn btn-sm btn-danger',
|
||||||
|
orientation: 'landscape',
|
||||||
|
pageSize: 'A4'
|
||||||
|
}),
|
||||||
|
$.extend(true, {}, exportConfig, { extend: 'print', className: 'btn btn-sm btn-dark' })
|
||||||
|
];
|
||||||
|
|
||||||
|
// On vérifie si l'utilisateur a passé ses propres boutons
|
||||||
|
const finalButtons = (options && options.buttons) ? options.buttons : defaultButtons;
|
||||||
|
|
||||||
const instance = $table.DataTable($.extend(true, {
|
const instance = $table.DataTable($.extend(true, {
|
||||||
destroy: true, // Permet de réinitialiser la table si elle existe déjà
|
destroy: true,
|
||||||
responsive: true, // Adaptation mobile
|
responsive: true,
|
||||||
pageLength: 25, // Nombre de lignes par défaut
|
pageLength: 25,
|
||||||
order: [[0, "desc"]], // Tri par défaut sur la 1ère colonne
|
order: [[0, "desc"]],
|
||||||
dom: 'Bfrtip', // Positionnement des éléments (Buttons, filter, processing, table, info, pagination)
|
dom: 'Bfrtip',
|
||||||
language: translations[codeLangue] || translations.fr_FR,
|
language: translations[codeLangue] || translations.fr_FR,
|
||||||
columnDefs: [
|
columnDefs: [{ targets: hiddenTargets, visible: false }],
|
||||||
{ targets: hiddenTargets, visible: false } // Masque les colonnes techniques
|
fixedHeader: { header: true, footer: true },
|
||||||
],
|
buttons: finalButtons // On utilise la liste filtrée
|
||||||
// Activation du Header et Footer collants (Nécessite l'extension FixedHeader)
|
|
||||||
fixedHeader: {
|
|
||||||
header: true,
|
|
||||||
footer: true
|
|
||||||
},
|
|
||||||
buttons: [
|
|
||||||
$.extend(true, {}, exportConfig, { extend: 'copy', className: 'btn btn-sm btn-light' }),
|
|
||||||
$.extend(true, {}, exportConfig, { extend: 'excel', className: 'btn btn-sm btn-success' }),
|
|
||||||
$.extend(true, {}, exportConfig, {
|
|
||||||
extend: 'pdf',
|
|
||||||
className: 'btn btn-sm btn-danger',
|
|
||||||
orientation: 'landscape',
|
|
||||||
pageSize: 'A4'
|
|
||||||
}),
|
|
||||||
$.extend(true, {}, exportConfig, { extend: 'print', className: 'btn btn-sm btn-dark' })
|
|
||||||
]
|
|
||||||
}, options));
|
}, options));
|
||||||
|
|
||||||
// 6. Recalcul de la largeur des colonnes après le rendu initial
|
|
||||||
$table.on('init.dt', function () {
|
$table.on('init.dt', function () {
|
||||||
if (instance && instance.responsive) {
|
if (instance && instance.responsive) {
|
||||||
instance.columns.adjust();
|
instance.columns.adjust();
|
||||||
|
|
|
||||||
|
|
@ -710,7 +710,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.03.29.01"></script>
|
<script src="/Js/fonctions.js?ver=2026.03.29.02"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
raffraichier_gabarit();
|
raffraichier_gabarit();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user