Files
opensem/resources/shop/js/include/datatable.js
2025-10-04 10:13:38 +02:00

147 lines
3.4 KiB
JavaScript

function getDatatablesSelector(module) {
return '#' + module + '-table';
}
function getDataTables(options,route,module, nobuttons) {
var params = {
ajax: {
url: route,
data: function ( d ) {
d.where = $('#where').val();
}
},
buttons: (!nobuttons) ? getDatatablesButtons() : [],
responsive: false,
keys: false,
autoWidth: true,
processing: true,
serverSide: true,
lengthChange: true,
lengthMenu: [
[ 10, 25, 50, 100, -1],
[ '10 lignes', '25 lignes', '50 lignes', '100 lignes', 'Tous']
],
deferRender: true,
stateSave: false,
sDom: options['dom'] ? options['dom'] : getDatatablesDomDefault(),
fixedHeader: false,
fixedColumns: options['fixedColumns'],
colReorder: false,
scrollX: true,
scrollY: "70vh",
scrollCollapse: true,
searchDelay: 300,
select: false,
columns: options['columns'],
language: datatables_lang,
rowId: 'id',
};
/* // DOM Position key index //
l - Length changing (dropdown)
f - Filtering input (search)
t - The Table! (datatable)
i - Information (records)
p - Pagination (paging)
r - pRocessing
< and > - div elements
<"#id" and > - div with an id
<"class" and > - div with a class
<"#id.class" and > - div with an id and class
Also see: http://legacy.datatables.net/usage/features
*/
if (options['order']) {
params.order = options['order'];
}
// console.log(params);
var Table = $('#'+module+'-table').DataTable(params);
handleDataTablesFilter(Table,module);
// Table.buttons().container().appendTo( $('.col-sm-6:eq(0)'));
return Table;
}
function handleDataTablesFilter(Table) {
$(Table.table().container()).on('change keyup', 'thead input', function() {
Table.column( $(this).parent().index()+':visible' ).search( this.value ).draw();
});
$(Table.table().container()).on('change', 'thead select', function() {
Table.column( $(this).parent().index()+':visible' ).search( this.value ).draw();
});
$('[data-toggle="popover"]').popover({html: true});
};
function getDatatablesButtons() {
return ['pageLength',
{
extend: 'copyHtml5',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-files-o fa-lg"></i>',
titleAttr: 'Copier',
className: 'hidden-xs',
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-file-excel-o fa-lg"></i>',
titleAttr: 'Excel',
className: 'hidden-xs',
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-file-pdf-o fa-lg"></i>',
titleAttr: 'PDF',
className: 'hidden-xs',
},
{
extend: 'print',
text: '<i class="fa fa-print fa-lg"></i>',
titleAttr: 'Imprimer',
className: 'hidden-xs',
},
{
extend: 'colvis',
text: '<i class="fa fa-columns fa-lg"></i>',
titleAttr: 'Colonnes',
columns: ':not(.fixed)'
}
];
}
function getDatatablesDomDefault(nobuttons) {
dom = (!nobuttons) ? getDatatablesHeaderDefault() : '';
dom += "t";
dom += getDatatablesFooterDefault();
return dom;
}
function getDatatablesHeaderDefault() {
return "<' row dt-toolbar-header'<'col-md-4 tool'B><'col-md-4'<'toolbar'>><'col-md-4 text-right add'>r>";
}
function getDatatablesFooterDefault() {
return "<'row dt-toolbar-footer'<'col-md-6'i><'col-md-6'p>>";
}
function getDatatableLang() {
return "/assets/plugins/datatables_lang/" + getLang() + '.json';
}