From e0a3b2a8dc6962f03c05107f44934bc5c23ee299 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez Date: Fri, 23 Apr 2021 14:54:40 +0200 Subject: [PATCH] [BUGFIX] Wait for DOM being ready before initializing DataTables Resolves: WEBSITE-299 Releases: master, 10 --- .../Private/JavaScript/backend/Datatables.js | 82 ++++++++++--------- Resources/Public/JavaScript/Datatables.js | 2 +- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/Resources/Private/JavaScript/backend/Datatables.js b/Resources/Private/JavaScript/backend/Datatables.js index 4f367f95..a4fe58c4 100644 --- a/Resources/Private/JavaScript/backend/Datatables.js +++ b/Resources/Private/JavaScript/backend/Datatables.js @@ -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 = $('') - .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 = $('') + .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('') - }); - } - }); - } + + 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('') + }); + } + }); + } + }); }); diff --git a/Resources/Public/JavaScript/Datatables.js b/Resources/Public/JavaScript/Datatables.js index 702e482c..36d13945 100644 --- a/Resources/Public/JavaScript/Datatables.js +++ b/Resources/Public/JavaScript/Datatables.js @@ -1,2 +1,2 @@ /*! For license information please see Datatables.js.LICENSE.txt */ -define(["jquery"],(function(t){return function(){var e={855:function(t,e,n){var a,r;a=[n(273),n(920)],void 0===(r=function(t){return function(t,e,n,a){"use strict";var r=t.fn.dataTable;return t.extend(!0,r.defaults,{dom:"<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>",renderer:"bootstrap"}),t.extend(r.ext.classes,{sWrapper:"dataTables_wrapper form-inline dt-bootstrap",sFilterInput:"form-control input-sm",sLengthSelect:"form-control input-sm",sProcessing:"dataTables_processing panel panel-default"}),r.ext.renderer.pageButton.bootstrap=function(e,o,i,l,s,u){var c,f,d,h=new r.Api(e),p=e.oClasses,g=e.oLanguage.oPaginate,b=e.oLanguage.oAria.paginate||{},v=0,m=function(n,a){var r,o,l,d,S=function(e){e.preventDefault(),t(e.currentTarget).hasClass("disabled")||h.page()==e.data.action||h.page(e.data.action).draw("page")};for(r=0,o=a.length;r0?"":" disabled");break;case"previous":c=g.sPrevious,f=d+(s>0?"":" disabled");break;case"next":c=g.sNext,f=d+(s",{class:p.sPageButton+" "+f,id:0===i&&"string"==typeof d?e.sTableId+"_"+d:null}).append(t("",{href:"#","aria-controls":e.sTableId,"aria-label":b[d],"data-dt-idx":v,tabindex:e.iTabIndex}).html(c)).appendTo(n),e.oApi._fnBindAction(l,{action:d},S),v++)}};try{d=t(o).find(n.activeElement).data("dt-idx")}catch(t){}m(t(o).empty().html('