Skip to content

Commit

Permalink
[BUGFIX] Wait for DOM being ready before initializing DataTables
Browse files Browse the repository at this point in the history
Resolves: WEBSITE-299
Releases: master, 10
  • Loading branch information
andreaskienast committed Apr 23, 2021
1 parent b7ab3e7 commit e0a3b2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
82 changes: 42 additions & 40 deletions Resources/Private/JavaScript/backend/Datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,47 @@ import $ from 'jquery';
import 'datatables.net';
import 'datatables.net-bs';

$('.dataTables').DataTable({
"columns": function () {
return $(this).data('columns')
},
"pageLength": 25,
"initComplete": function () {
this.api().columns().every(function () {
var column = this;
if ($(column.header()).data('filter') === true) {
var select = $('<select><option value="">' + $(column.header()).text() + '</option></select>')
.appendTo($(column.header()).empty())
.on('click', function (e) {
e.stopPropagation();
})
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column.search(val ? val : '', true, false).draw();
});

var values = [];
column.nodes().each(function (content) {
var filter = $(content).data('filter');
if (typeof filter !== "undefined") {
var entries = filter.split(',');
entries.forEach(function (entry) {
if (entry.trim() !== '') values.push(entry.trim());
$(function() {
$('.dataTables').DataTable({
"columns": function () {
return $(this).data('columns')
},
"pageLength": 25,
"initComplete": function () {
this.api().columns().every(function () {
var column = this;
if ($(column.header()).data('filter') === true) {
var select = $('<select><option value="">' + $(column.header()).text() + '</option></select>')
.appendTo($(column.header()).empty())
.on('click', function (e) {
e.stopPropagation();
})
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column.search(val ? val : '', true, false).draw();
});
}
});
values = values.filter(function (value, index, self) {
return self.indexOf(value) === index;
});
$(values).sort().each(function () {
var value = this;
select.append('<option value="' + value + '">' + value + '</option>')
});
}
});
}

var values = [];
column.nodes().each(function (content) {
var filter = $(content).data('filter');
if (typeof filter !== "undefined") {
var entries = filter.split(',');
entries.forEach(function (entry) {
if (entry.trim() !== '') values.push(entry.trim());
});
}
});
values = values.filter(function (value, index, self) {
return self.indexOf(value) === index;
});
$(values).sort().each(function () {
var value = this;
select.append('<option value="' + value + '">' + value + '</option>')
});
}
});
}
});
});
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/Datatables.js

Large diffs are not rendered by default.

0 comments on commit e0a3b2a

Please sign in to comment.