df
This commit is contained in:
parent
82c0d8f244
commit
9a201146bf
|
|
@ -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;
|
if ($(selector).length === 0) return;
|
||||||
|
|
||||||
// Détection automatique : la barre de recherche personnalisée existe-t-elle ?
|
|
||||||
var hasGlobalSearch = $('#globalSearch').length > 0;
|
var hasGlobalSearch = $('#globalSearch').length > 0;
|
||||||
|
|
||||||
if ($.fn.DataTable.isDataTable(selector)) {
|
if ($.fn.DataTable.isDataTable(selector)) {
|
||||||
$(selector).DataTable().destroy();
|
$(selector).DataTable().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration du DOM :
|
|
||||||
// Si hasGlobalSearch est vrai, on retire 'f' (recherche native)
|
|
||||||
var domStructure = hasGlobalSearch
|
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-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-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({
|
var table = $(selector).DataTable({
|
||||||
"dom": domStructure,
|
"dom": domStructure,
|
||||||
|
"order": orderConfig, // <--- AJOUT ICI
|
||||||
"buttons": [
|
"buttons": [
|
||||||
{
|
{
|
||||||
extend: 'excelHtml5',
|
extend: 'excelHtml5',
|
||||||
|
|
@ -92181,7 +92189,6 @@ function initSmartTable(selector = '.datatable-inter', pageTitle = 'Export Donn
|
||||||
"pageLength": 10,
|
"pageLength": 10,
|
||||||
"autoWidth": false,
|
"autoWidth": false,
|
||||||
"drawCallback": function() {
|
"drawCallback": function() {
|
||||||
// Style uniquement si la recherche native est affichée
|
|
||||||
if (!hasGlobalSearch) {
|
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');
|
$('.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) {
|
if (hasGlobalSearch) {
|
||||||
$('#globalSearch').off('keyup').on('keyup', function() {
|
$('#globalSearch').off('keyup').on('keyup', function() {
|
||||||
table.search(this.value).draw();
|
table.search(this.value).draw();
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
window.addEventListener('load', function() {
|
window.addEventListener('load', function() {
|
||||||
if (typeof jQuery !== 'undefined') {
|
if (typeof jQuery !== 'undefined') {
|
||||||
// La fonction détecte seule #globalSearch et lie la recherche !
|
// La fonction détecte seule #globalSearch et lie la recherche !
|
||||||
initSmartTable('.table', 'Gestion des Bons');
|
initSmartTable('.table', 'Gestion des Bons', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user