125 lines
3.1 KiB
JavaScript
125 lines
3.1 KiB
JavaScript
let table;
|
|
if (typeof hidesearch === "undefined") {
|
|
var hidesearch;
|
|
hidesearch = [100];
|
|
}
|
|
|
|
|
|
if (typeof pageLength === "undefined") {
|
|
var pageLength;
|
|
pageLength = 25;
|
|
}
|
|
|
|
if (typeof cstmdom === "undefined") {
|
|
var cstmdom;
|
|
cstmdom = "flBrtip";
|
|
|
|
}
|
|
if (typeof columndefs === "undefined") {
|
|
var columndefs;
|
|
columndefs = "";
|
|
|
|
}
|
|
|
|
if (typeof columnfilter === "undefined") {
|
|
var columnfilter;
|
|
columnfilter = "";
|
|
}
|
|
if (typeof columnoptions === "undefined") {
|
|
var columnoptions;
|
|
columnoptions = "";
|
|
}
|
|
|
|
$('#filterrow th').each(function (i) {
|
|
let title = $('#datatable thead th').eq($(this).index()).text();
|
|
|
|
if (hidesearch.includes($(this).index())) {
|
|
|
|
} else if (columnfilter.includes($(this).index())) {
|
|
$(this).html('<select style="padding: 0;height: 28px;;text-align: center;" id="selectsearch" class="form-control form-control-select form-control-special" data-index="' + i + '">' + columnoptions + '</select>');
|
|
|
|
} else {
|
|
$(this).html('<input type="text" placeholder="' + title + '" class="form-control" data-index="' + i + '" value="" />');
|
|
}
|
|
});
|
|
|
|
table = $('#datatable').DataTable({
|
|
responsive: {
|
|
breakpoints: [
|
|
{name: 'desktop', width: Infinity},
|
|
{name: 'tablet', width: 1024},
|
|
{name: 'fablet', width: 768},
|
|
{name: 'phone', width: 480}
|
|
]
|
|
},
|
|
pageLength: pageLength,
|
|
buttons: [
|
|
{
|
|
extend: 'excelHtml5',
|
|
text: 'XLSX Export',
|
|
className: 'btn-success margina d-none d-lg-block',
|
|
exportOptions: {
|
|
columns: ['th:not(:last-child)'],
|
|
format: {
|
|
body: function (data, row, column, node) {
|
|
data = $('<p>' + data + '</p>').text();
|
|
return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
], columnDefs: [
|
|
columndefs
|
|
],
|
|
"language": {
|
|
"url": "/datatables/json/german.json?v1"
|
|
},
|
|
orderCellsTop: true,
|
|
stateSave: true,
|
|
stateDuration: 60 * 60 * 24 * 30,
|
|
"initComplete": function () {
|
|
$('#datatable_filter').append('<i id="clear_cookie" class="fas fa-times clear-fa" title="Filter löschen" aria-hidden="true" ></i>');
|
|
$('#clear_cookie').click(function () {
|
|
$('#filterrow input').val('');
|
|
$('#filterrow select').val('');
|
|
table.search('').columns().search('').draw();
|
|
});
|
|
},
|
|
"dom": cstmdom
|
|
|
|
});
|
|
|
|
$('#filterrow').on('keyup', 'input', function () {
|
|
|
|
table
|
|
.column($(this).data('index'))
|
|
.search(this.value)
|
|
.draw();
|
|
|
|
|
|
});
|
|
|
|
$('#selectsearch').change(function () {
|
|
table
|
|
.column($(this).data('index'))
|
|
.search(this.value)
|
|
.draw();
|
|
|
|
|
|
});
|
|
let state = table.state.loaded();
|
|
if (state) {
|
|
table.columns().eq(0).each(function (colIdx) {
|
|
var colSearch = state.columns[colIdx].search;
|
|
|
|
if (colSearch.search) {
|
|
|
|
|
|
$('#filterrow').find("[data-index='" + colIdx + "']").val(colSearch.search);
|
|
|
|
|
|
}
|
|
});
|
|
|
|
table.draw();
|
|
} |