Files
eveAI/eveai_app/static/assets/js/eveai-tabulator-setup.js
2025-07-14 18:58:54 +02:00

84 lines
3.4 KiB
JavaScript

/**
* EveAI Tabulator Setup
* Standaard Tabulator configuratie voor consistente tabelweergaven
*/
document.addEventListener('DOMContentLoaded', function() {
// Controleer of Tabulator is geladen
if (typeof Tabulator !== 'function') {
console.warn('Tabulator is niet geladen - overslaan van initialisatie');
return;
}
// Zorg ervoor dat de modules correct zijn gedefinieerd
if (!Tabulator.modules) {
Tabulator.modules = {};
}
if (!Tabulator.modules.format) {
Tabulator.modules.format = { formatters: {} };
} else if (!Tabulator.modules.format.formatters) {
Tabulator.modules.format.formatters = {};
}
// Registreer algemene Tabulator opties en formatters
// Gebruik rechtstreekse toewijzing i.p.v. extendModule indien deze functie niet beschikbaar is
if (typeof Tabulator.extendModule === 'function') {
try {
Tabulator.extendModule("format", "formatters", {
// Aangepaste formatter voor boolean waarden met mooie iconen
"boolean": function(cell, formatterParams){
const value = cell.getValue();
if (value === true || value === 'true' || value === 1 || value === '1') {
return '<i class="fas fa-check text-success"></i>';
} else if (value === false || value === 'false' || value === 0 || value === '0') {
return '<i class="fas fa-times text-danger"></i>';
}
return ''; // Geef lege string terug voor null/undefined waarden
}
});
} catch (e) {
console.warn('Fout bij extendModule:', e);
// Fallback: rechtstreeks formatters toevoegen
Tabulator.modules.format.formatters.boolean = function(cell, formatterParams){
const value = cell.getValue();
if (value === true || value === 'true' || value === 1 || value === '1') {
return '<i class="fas fa-check text-success"></i>';
} else if (value === false || value === 'false' || value === 0 || value === '0') {
return '<i class="fas fa-times text-danger"></i>';
}
return '';
};
}
} else {
// Directe toewijzing als extendModule niet beschikbaar is
Tabulator.modules.format.formatters.boolean = function(cell, formatterParams){
const value = cell.getValue();
if (value === true || value === 'true' || value === 1 || value === '1') {
return '<i class="fas fa-check text-success"></i>';
} else if (value === false || value === 'false' || value === 0 || value === '0') {
return '<i class="fas fa-times text-danger"></i>';
}
return '';
};
}
// Definieer standaard tabelconfiguratie
Tabulator.defaultOptions = {
...Tabulator.defaultOptions,
layout: "fitColumns",
responsiveLayout: false,
pagination: "local",
paginationSize: 25,
paginationSizeSelector: [10, 25, 50, 100],
movableColumns: true,
tooltips: false,
placeholder: "No Data Available",
// Verbeterde virtuele DOM-instellingen voor betere prestaties
renderVerticalBuffer: 20,
virtualDomBuffer: 80
};
console.log('EveAI Tabulator Setup successfully loaded');
});