183 lines
5.4 KiB
JavaScript
183 lines
5.4 KiB
JavaScript
let table;
|
|
if (typeof adminc === "undefined") {
|
|
var adminc;
|
|
adminc = 0;
|
|
}
|
|
if (typeof initc === "undefined") {
|
|
var initc;
|
|
initc = 1;
|
|
}
|
|
if (typeof hidesearch === "undefined") {
|
|
var hidesearch;
|
|
hidesearch = [100];
|
|
}
|
|
if (typeof hidesearch === "undefined") {
|
|
var cstmbuttons;
|
|
cstmbuttons = [];
|
|
}
|
|
|
|
|
|
if (typeof pageLength === "undefined") {
|
|
var pageLength;
|
|
pageLength = -1;
|
|
}
|
|
|
|
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 selectsearch" data-index="' + i + '">' + columnoptions + '</select>');
|
|
|
|
} else {
|
|
$(this).html('<input type="text" placeholder="' + title + '" class="form-control" data-index="' + i + '" value="" />');
|
|
}
|
|
});
|
|
|
|
|
|
table = $('#datatable').DataTable({
|
|
fixedHeader: {
|
|
header: true,
|
|
headerOffset: $('#topnav').outerHeight()
|
|
|
|
}, lengthMenu: [
|
|
[25, 50, 100, -1],
|
|
[25, 50, 100, 'All']
|
|
],
|
|
pageLength: pageLength,
|
|
columnDefs: [
|
|
columndefs
|
|
],
|
|
"language": {
|
|
"url": "/datatables/json/german.json?v2"
|
|
},
|
|
orderCellsTop: true,
|
|
stateSave: true,
|
|
stateDuration: 60 * 60 * 24 * 30,
|
|
"initComplete": function () {
|
|
$('.dt-search').append('<i id="clear_cookie" class="fas fa-times clear-fa" title="Filter löschen" aria-hidden="true" ></i>');
|
|
$('.dt-search').addClass('d-inline-block');
|
|
$.each(cstmbuttons, function (index, value) {
|
|
$('.dt-buttons').append(value);
|
|
});
|
|
$('#dt-length-0').addClass('form-control-sm');
|
|
$('#clear_cookie').click(function () {
|
|
$('#filterrow input').val('');
|
|
$('#filterrow select').val('');
|
|
table.search('').columns().search('').draw();
|
|
});
|
|
if (initc === 2) {
|
|
$('.buttons-excel').closest('div').append('<div ><button id="month-complete" class="btn btn-danger margina">Monats Abschluss</button></div>');
|
|
$('.buttons-excel').closest('div').append('<div ><button id="open-workdays" class="btn btn-info margina">Offene Arbeitstage</button></div>');
|
|
$('.buttons-excel').closest('div').append('<div ><button id="bmd-export" class="btn btn-info margina">BMD Import</button></div>');
|
|
$('.buttons-excel').closest('div').append('<div ><button id="bmd-export-nlz" class="btn btn-info margina">BMD NLZ Import</button></div>');
|
|
}
|
|
else if (initc === 3) {
|
|
$('.buttons-excel').closest('div').append('<div ><button id="bmd-export" class="btn btn-info margina">BMD Import</button></div>');
|
|
$('.buttons-excel').closest('div').append('<div ><button id="bmd-export-nlz" class="btn btn-info margina">BMD NLZ Import</button></div>');
|
|
if (adminc===1)
|
|
{
|
|
$('.buttons-excel').closest('div').prepend('<div ><button id="month-abort" class="btn btn-danger margina">Abschluss Abbrechen</button></div>');
|
|
}
|
|
}
|
|
},
|
|
layout:
|
|
{
|
|
topStart: {
|
|
search: {
|
|
placeholder: ''
|
|
}, 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) {
|
|
console.log(data);
|
|
data = $('<p>' + data + '</p>').text();
|
|
|
|
return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
topEnd: {
|
|
pageLength: true
|
|
}
|
|
}
|
|
});
|
|
|
|
$(window).scroll(function () {
|
|
var height = $(window).scrollTop();
|
|
|
|
if (height > 200) {
|
|
if ($('#filterrow').is(':visible')) {
|
|
$('#filterrow').hide();
|
|
}
|
|
|
|
} else {
|
|
if ($('#filterrow').is(':hidden')) {
|
|
$('#filterrow').show();
|
|
}
|
|
}
|
|
});
|
|
|
|
$('#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();
|
|
} |