Skip to content

Commit c7ebf3a

Browse files
authored
Merge pull request #5812 from Laravel-Backpack/fix-datatable-dom-property
Fix datatable dom property
2 parents fb5cf29 + bc30cfe commit c7ebf3a

File tree

3 files changed

+175
-34
lines changed

3 files changed

+175
-34
lines changed

src/resources/assets/css/common.css

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,50 @@ form .select2.select2-container {
6161
}
6262

6363
/*Table - List View*/
64+
.dataTables_wrapper {
65+
position: relative;
66+
isolation: isolate;
67+
}
68+
6469
.dataTables_wrapper div.row .col-sm-12 {
6570
position: relative;
6671
}
72+
73+
.dataTables_wrapper .table-responsive {
74+
position: relative;
75+
}
76+
77+
.dataTables_wrapper table.dataTable {
78+
position: relative;
79+
z-index: 1;
80+
}
81+
82+
/* Ensure any processing indicator within or related to table wrapper covers full area */
83+
.dataTables_wrapper,
84+
div[id$="_wrapper"] {
85+
position: relative !important;
86+
}
87+
88+
.dataTables_wrapper > .dataTables_processing,
89+
.dataTables_wrapper > .dt-processing,
90+
.dataTables_wrapper .dataTables_processing,
91+
.dataTables_wrapper .dt-processing,
92+
div[id$="_wrapper"] > .dataTables_processing,
93+
div[id$="_wrapper"] > .dt-processing,
94+
div[id$="_wrapper"] .dataTables_processing,
95+
div[id$="_wrapper"] .dt-processing {
96+
position: absolute !important;
97+
top: 0 !important;
98+
left: 0 !important;
99+
right: 0 !important;
100+
bottom: 60px !important;
101+
width: 100% !important;
102+
height: calc(100% - 60px) !important;
103+
transform: none !important;
104+
margin: 0 !important;
105+
z-index: 1000 !important;
106+
inset: unset !important;
107+
}
67108
.navbar-filters {
68109
min-height: 25px;
69110
border-radius: 0;
@@ -629,42 +670,59 @@ table.dataTable tr th:first-child, table.dataTable tr td:first-child, table.data
629670
padding-left: 0.6rem;
630671
}
631672

673+
/* Processing indicator - global styles */
632674
.dataTables_processing,
633675
.dt-processing {
676+
position: absolute !important;
634677
background: rgba(255, 255, 255, 0.8) !important;
635-
color: transparent !important; /* Hide any text */
636678
border: none !important;
637-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1) !important;
638-
border-radius: 5px !important;
639-
width: 100% !important;
640-
height: 100% !important;
641-
position: absolute !important;
642-
top: 0 !important;
643-
left: 0 !important;
644-
transform: none !important;
645-
margin: 0 !important;
679+
box-shadow: none !important;
680+
border-radius: 0 !important;
646681
padding: 0 !important;
647-
z-index: 999 !important;
682+
z-index: 1000 !important;
648683
display: flex !important;
649684
justify-content: center !important;
650685
align-items: center !important;
686+
overflow: hidden !important;
687+
/* Aggressive text hiding */
688+
font-size: 0 !important;
689+
line-height: 0 !important;
690+
color: transparent !important;
691+
text-indent: -9999px !important;
692+
white-space: nowrap !important;
693+
text-shadow: none !important;
694+
text-decoration: none !important;
651695
}
652696

697+
/* Hide ALL text content and children */
698+
.dataTables_processing *:not(img),
699+
.dt-processing *:not(img),
700+
.dataTables_processing::before,
701+
.dataTables_processing::after,
702+
.dt-processing::before,
703+
.dt-processing::after {
704+
display: none !important;
705+
visibility: hidden !important;
706+
opacity: 0 !important;
707+
font-size: 0 !important;
708+
color: transparent !important;
709+
text-indent: -9999px !important;
710+
}
711+
712+
/* Show only spinner image */
653713
.dataTables_processing img,
654714
.dt-processing img {
655715
display: block !important;
656-
width: 30px !important;
657-
height: 30px !important;
716+
width: 40px !important;
717+
height: 40px !important;
658718
opacity: 1 !important;
659719
visibility: visible !important;
660720
margin: 0 auto !important;
721+
position: relative !important;
722+
z-index: 1001 !important;
661723
}
662724

663-
.dataTables_processing > *:not(img),
664-
.dt-processing > *:not(img) {
665-
display: none !important;
666-
}
667-
725+
/* Hide when not active */
668726
.dataTables_processing:not([style*="block"]),
669727
.dt-processing:not([style*="block"]) {
670728
display: none !important;
@@ -812,18 +870,14 @@ div.dt-scroll-body {
812870
margin-bottom: 0;
813871
}
814872

815-
.dt-buttons {
816-
margin-bottom: 8px;
817-
}
818-
819873
/* Adjust table headers */
820874
.dataTable thead th {
821875
font-size: 0.70em;
822876
font-weight: 700;
823877
}
824878

825879
/* Make export and column visibility buttons smaller */
826-
.dataTables_wrapper .dt-buttons .btn {
880+
.dt-container .dt-buttons .btn-group .btn {
827881
padding: 0.25rem 0.5rem;
828882
font-size: 0.875rem;
829883
}

src/resources/views/crud/components/datatable/datatable_logic.blade.php

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,23 @@ functionsToRunOnDataTablesDrawEvent: [],
305305
"colvis": "{{ trans('backpack::crud.export.column_visibility') }}"
306306
},
307307
},
308-
dom:
309-
"<'row hidden'<'col-sm-6'i><'col-sm-6 d-print-none'f>>" +
310-
"<'table-content row'<'col-sm-12'tr>>" +
311-
"<'table-footer row mt-2 d-print-none align-items-center '<'col-sm-12 col-md-4'l><'col-sm-0 col-md-4 text-center'B><'col-sm-12 col-md-4 'p>>",
308+
layout: {
309+
topStart: null,
310+
topEnd: null,
311+
bottomEnd: null,
312+
bottomStart: null,
313+
bottom: [
314+
'pageLength',
315+
{
316+
buttons: config.exportButtons ? window.crud.exportButtonsConfig : []
317+
},
318+
{
319+
paging: {
320+
firstLast: false,
321+
}
322+
}
323+
]
324+
},
312325
buttons: []
313326
};
314327
@@ -406,7 +419,7 @@ functionsToRunOnDataTablesDrawEvent: [],
406419
407420
// Configure export buttons if present
408421
if (config.exportButtons) {
409-
dataTableConfig.buttons = window.crud.exportButtonsConfig;
422+
dataTableConfig.layout.bottom.buttons = window.crud.exportButtonsConfig;
410423
}
411424
412425
@@ -429,6 +442,33 @@ functionsToRunOnDataTablesDrawEvent: [],
429442
};
430443
}
431444
445+
// Add initComplete callback to fix processing indicator positioning
446+
dataTableConfig.initComplete = function(settings, json) {
447+
// Move processing indicator into table wrapper if it exists outside
448+
const tableWrapper = document.querySelector('#' + tableId + '_wrapper');
449+
const processingIndicator = document.querySelector('.dataTables_processing, .dt-processing');
450+
451+
if (tableWrapper && processingIndicator && !tableWrapper.contains(processingIndicator)) {
452+
// Move the processing indicator into the wrapper
453+
tableWrapper.appendChild(processingIndicator);
454+
455+
// Ensure proper positioning
456+
processingIndicator.style.position = 'absolute';
457+
processingIndicator.style.top = '0';
458+
processingIndicator.style.left = '0';
459+
processingIndicator.style.right = '0';
460+
processingIndicator.style.bottom = '0';
461+
processingIndicator.style.width = 'auto';
462+
processingIndicator.style.height = 'auto';
463+
processingIndicator.style.zIndex = '1000';
464+
}
465+
466+
// Call any existing initComplete function
467+
if (typeof window.crud.initCompleteCallback === 'function') {
468+
window.crud.initCompleteCallback.call(this, settings, json);
469+
}
470+
};
471+
432472
// Store the dataTableConfig in the config object for future reference
433473
config.dataTableConfig = dataTableConfig;
434474
@@ -526,8 +566,6 @@ function setupTableUI(tableId, config) {
526566
}
527567
});
528568
window.dispatchEvent(event);
529-
// move the bottom buttons before pagination
530-
$(`#bottom_buttons_${tableId}`).insertBefore($(`#${tableId}_wrapper .row:last-child`));
531569
}
532570
533571
// Function to set up table event handlers
@@ -629,6 +667,55 @@ function setupTableEvents(tableId, config) {
629667
}
630668
}).dataTable();
631669
670+
$(`#${tableId}`).on('processing.dt', function(e, settings, processing) {
671+
if (processing) {
672+
setTimeout(function() {
673+
const tableWrapper = document.querySelector('#' + tableId + '_wrapper');
674+
const processingIndicator = document.querySelector('.dataTables_processing, .dt-processing');
675+
676+
if (tableWrapper && processingIndicator) {
677+
if (!tableWrapper.contains(processingIndicator)) {
678+
tableWrapper.appendChild(processingIndicator);
679+
}
680+
681+
processingIndicator.style.cssText = `
682+
position: absolute !important;
683+
top: 0 !important;
684+
left: 0 !important;
685+
right: 0 !important;
686+
bottom: 60px !important;
687+
width: 100% !important;
688+
height: calc(100% - 60px) !important;
689+
z-index: 1000 !important;
690+
transform: none !important;
691+
margin: 0 !important;
692+
padding: 0 !important;
693+
display: flex !important;
694+
justify-content: center !important;
695+
align-items: center !important;
696+
background: rgba(255, 255, 255, 0.8) !important;
697+
font-size: 0 !important;
698+
color: transparent !important;
699+
text-indent: -9999px !important;
700+
overflow: hidden !important;
701+
`;
702+
703+
tableWrapper.style.position = 'relative';
704+
705+
const allChildren = processingIndicator.querySelectorAll('*:not(img)');
706+
allChildren.forEach(child => {
707+
child.style.cssText = 'display: none !important; visibility: hidden !important; opacity: 0 !important;';
708+
});
709+
710+
const images = processingIndicator.querySelectorAll('img');
711+
images.forEach(img => {
712+
img.style.cssText = 'display: block !important; visibility: visible !important; opacity: 1 !important; width: 40px !important; height: 40px !important; margin: 0 auto !important;';
713+
});
714+
}
715+
}, 10);
716+
}
717+
});
718+
632719
// when datatables-colvis (column visibility) is toggled
633720
$(`#${tableId}`).on('column-visibility.dt', function(event) {
634721
if (table.responsive) {

src/resources/views/crud/inc/export_buttons.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
{
5656
extend: 'collection',
5757
text: '<i class="la la-download"></i> {{ trans('backpack::crud.export.export') }}',
58+
className: 'buttons-collection dropdown-toggle',
5859
dropup: true,
5960
buttons: [
6061
{
@@ -159,6 +160,7 @@
159160
,{
160161
extend: 'colvis',
161162
text: '<i class="la la-eye-slash"></i> {{ trans('backpack::crud.export.column_visibility') }}',
163+
className: 'buttons-collection dropdown-toggle',
162164
columns: function ( idx, data, node ) {
163165
return $(node).attr('data-can-be-visible-in-table') == 'true';
164166
},
@@ -173,14 +175,12 @@
173175
var table = window.crud.tables[tableId];
174176
175177
if (!table || !table.buttons) return;
176-
177178
table.buttons().each(function(button) {
178179
if (button.node.className.indexOf('buttons-columnVisibility') == -1 && button.node.nodeName=='BUTTON') {
179-
button.node.className = button.node.className + " btn-sm";
180+
button.node.className = button.node.className.replace('btn-secondary', 'btn-sm');
180181
}
181182
});
182-
183-
$(`#${tableId}_wrapper .dt-buttons`).appendTo($('.datatable_button_stack'));
183+
184184
$('.dt-buttons').addClass('d-xs-block')
185185
.addClass('d-sm-inline-block')
186186
.addClass('d-md-inline-block')

0 commit comments

Comments
 (0)