Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump DataTables version & fix header alignment #5724

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/resources/assets/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ form .select2.select2-container {
position: relative;
}

#crudTable_processing.dataTables_processing.card {
#crudTable_processing.dt-processing.card {
all: unset;
position: absolute;
background: rgba(255, 255, 255, 0.9);
Expand All @@ -77,15 +77,19 @@ form .select2.select2-container {
border-radius: 5px;
}

#crudTable_processing.dataTables_processing.card > img {
table.fixedHeader-floating, table.fixedHeader-locked {
background-color: white;
}

#crudTable_processing.dt-processing.card > img {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

#crudTable_processing.dataTables_processing.card > div {
#crudTable_processing.dt-processing.card > div {
display: none !important;
}

Expand Down Expand Up @@ -175,6 +179,19 @@ form .select2.select2-container {
border: 0;
}

#crudTable_wrapper > div.table-footer > div:nth-child(1) > div.dt-length {
display: flex;
gap: .50rem;
}

#crudTable_wrapper > div.table-footer > div:nth-child(1) > div.dt-length select {
width: 4rem;
}

#crudTable_wrapper > div.table-footer > div:nth-child(1) > div.dt-length > label{
white-space: nowrap;
}

/*/Table - List View/*/
.navbar-filters {
min-height: 25px;
Expand Down
46 changes: 30 additions & 16 deletions src/resources/views/crud/inc/datatables_logic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
@endphp

{{-- DATA TABLES SCRIPT --}}
@basset('https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js')
@basset('https://cdn.datatables.net/1.13.1/js/dataTables.bootstrap5.min.js')
@basset('https://cdn.datatables.net/responsive/2.4.0/js/dataTables.responsive.min.js')
@basset('https://cdn.datatables.net/responsive/2.4.0/css/responsive.dataTables.min.css')
@basset('https://cdn.datatables.net/fixedheader/3.3.1/js/dataTables.fixedHeader.min.js')
@basset('https://cdn.datatables.net/fixedheader/3.3.1/css/fixedHeader.dataTables.min.css')

@basset(base_path('vendor/backpack/crud/src/resources/assets/img/spinner.svg'), false)

@push('after_scripts')
@basset("https://cdn.datatables.net/2.1.8/js/dataTables.min.js")
@basset("https://cdn.datatables.net/2.1.8/js/dataTables.bootstrap5.min.js")
@basset("https://cdn.datatables.net/responsive/3.0.3/js/dataTables.responsive.min.js")
@basset('https://cdn.datatables.net/fixedheader/4.0.1/js/dataTables.fixedHeader.min.js')
@basset(base_path('vendor/backpack/crud/src/resources/assets/img/spinner.svg'), false)
@endpush

@push('before_styles')
@basset('https://cdn.datatables.net/2.1.8/css/dataTables.bootstrap5.min.css')
@basset("https://cdn.datatables.net/responsive/3.0.3/css/responsive.dataTables.min.css")
@basset('https://cdn.datatables.net/fixedheader/4.0.1/css/fixedHeader.dataTables.min.css')
@endpush
@push('after_scripts')
<script>
// here we will check if the cached dataTables paginator length is conformable with current paginator settings.
// datatables caches the ajax responses with pageLength in LocalStorage so when changing this
Expand Down Expand Up @@ -147,7 +152,7 @@ functionsToRunOnDataTablesDrawEvent: [],
@if ($crud->getResponsiveTable())
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.modal( {
display: DataTable.Responsive.display.modal( {
header: function ( row ) {
// show the content of the first column
// as the modal header
Expand Down Expand Up @@ -292,16 +297,16 @@ functionsToRunOnDataTablesDrawEvent: [],
window.crud.updateUrl(location.href);

// move search bar
$("#datatable_search_stack input").remove();
$("#crudTable_filter input").appendTo($('#datatable_search_stack .input-icon'));
$(".dt-search input").remove();
$(".dt-search input").appendTo($('#datatable_search_stack .input-icon'));
$("#datatable_search_stack input").removeClass('form-control-sm');
$("#crudTable_filter").remove();
$(".dt-search").remove();

// remove btn-secondary from export and column visibility buttons
$("#crudTable_wrapper .table-footer .btn-secondary").removeClass('btn-secondary');

// remove forced overflow on load
$(".navbar.navbar-filters + div").css('overflow','initial');
$(".navbar.navbar-filters + div").css('overflow','hidden');

// move "showing x out of y" info to header
@if($crud->getSubheading())
Expand Down Expand Up @@ -373,12 +378,20 @@ functionsToRunOnDataTablesDrawEvent: [],
$("#crudTable").removeClass('has-hidden-columns').addClass('has-hidden-columns');
}

// in datatables 2.0.3 the implementation was changed to use `replaceChildren`, for that reason scripts
// that came with the response are no longer executed, like the delete button script or any other ajax
// button created by the developer. For that reason, we move them to the end of the body
// ensuring they are re-evaluated on each draw event.
document.getElementById('crudTable').querySelectorAll('script').forEach(function(script) {
const newScript = document.createElement('script');
newScript.text = script.text;
document.body.appendChild(newScript);
});
}).dataTable();

// when datatables-colvis (column visibility) is toggled
// rebuild the datatable using the datatable-responsive plugin
$('#crudTable').on( 'column-visibility.dt', function (event) {
console.log('column-visibility.dt');
crud.table.responsive.rebuild();
} ).dataTable();

Expand Down Expand Up @@ -452,5 +465,6 @@ function formatActionColumnAsDropdown() {
});
}
</script>

@include('crud::inc.details_row_logic')
@endpush
22 changes: 13 additions & 9 deletions src/resources/views/crud/inc/export_buttons.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
@if ($crud->exportButtons())
@basset('https://cdn.datatables.net/buttons/2.3.3/css/buttons.bootstrap5.min.css')
@basset('https://cdn.datatables.net/buttons/2.3.3/js/dataTables.buttons.min.js')
@basset('https://cdn.datatables.net/buttons/2.3.3/js/buttons.bootstrap5.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/pdfmake.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/vfs_fonts.js')
@basset('https://cdn.datatables.net/buttons/2.3.2/js/buttons.html5.min.js')
@basset('https://cdn.datatables.net/buttons/2.3.2/js/buttons.print.min.js')
@basset('https://cdn.datatables.net/buttons/2.3.2/js/buttons.colVis.min.js')
@push('after_scripts')
@basset('https://cdn.datatables.net/buttons/3.2.0/js/dataTables.buttons.min.js')
@basset('https://cdn.datatables.net/buttons/3.2.0/js/buttons.bootstrap5.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/pdfmake.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/vfs_fonts.js')
@basset('https://cdn.datatables.net/buttons/3.2.0/js/buttons.html5.min.js')
@basset('https://cdn.datatables.net/buttons/3.2.0/js/buttons.print.min.js')
@basset('https://cdn.datatables.net/buttons/3.2.0/js/buttons.colVis.min.js')
@endpush
@push('after_styles')
@basset('https://cdn.datatables.net/buttons/3.2.0/css/buttons.bootstrap5.min.css')
@endpush
<script>
let dataTablesExportStrip = text => {
if ( typeof text !== 'string' ) {
Expand Down
6 changes: 4 additions & 2 deletions src/resources/views/crud/inc/filters_navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function normalizeAmpersand(string) {

// behaviour for ajax table
var new_url = '{{ url($crud->getOperationSetting("datatablesUrl").'/search') }}';
var ajax_table = $("#crudTable").DataTable();
var ajax_table = new DataTable('#crudTable');

// replace the datatables ajax url with new_url and reload it
ajax_table.ajax.url(new_url).load();
Expand All @@ -124,6 +124,9 @@ function normalizeAmpersand(string) {

// remove filters from URL
crud.updateUrl(new_url);

// hide the Remove filters button when no filter is active
$('#remove_filters_button').addClass('invisible');
});

// hide the Remove filters button when no filter is active
Expand All @@ -132,7 +135,6 @@ function normalizeAmpersand(string) {
$(".navbar-filters li[filter-name]").each(function () {
if ($(this).hasClass('active')) {
anyActiveFilters = true;
// console.log('ACTIVE FILTER');
}
});

Expand Down
3 changes: 0 additions & 3 deletions src/resources/views/crud/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class="{{ backpack_theme_config('classes.table') ?? 'table table-striped table-h

@section('after_styles')
{{-- DATA TABLES --}}
@basset('https://cdn.datatables.net/1.13.1/css/dataTables.bootstrap5.min.css')
@basset('https://cdn.datatables.net/fixedheader/3.3.1/css/fixedHeader.dataTables.min.css')
@basset('https://cdn.datatables.net/responsive/2.4.0/css/responsive.dataTables.min.css')

{{-- CRUD LIST CONTENT - crud_list_styles stack --}}
@stack('crud_list_styles')
Expand Down
Loading