diff --git a/src/config/backpack/operations/list.php b/src/config/backpack/operations/list.php index b1d227f104..9e3ebe8ffc 100644 --- a/src/config/backpack/operations/list.php +++ b/src/config/backpack/operations/list.php @@ -49,6 +49,9 @@ // Nest action buttons within a dropdown in actions column 'lineButtonsAsDropdown' => false, + // What is the minimum threshold of action buttons for nesting into a dropdown + 'lineButtonsAsDropdownThreshold' => 1, + // Show a "Reset" button next to the List operation subheading // (Showing 1 to 25 of 9999 entries. Reset) // that allows the user to erase local storage for that datatable, diff --git a/src/resources/views/crud/inc/datatables_logic.blade.php b/src/resources/views/crud/inc/datatables_logic.blade.php index b3b4f3c5fb..56aadc9b1a 100644 --- a/src/resources/views/crud/inc/datatables_logic.blade.php +++ b/src/resources/views/crud/inc/datatables_logic.blade.php @@ -407,16 +407,20 @@ function formatActionColumnAsDropdown() { const actionColumnIndex = $('#crudTable').find('th[data-action-column=true]').index(); if (actionColumnIndex === -1) return; + const minimumThreshold = $('#crudTable').data('line-buttons-as-dropdown-threshold'); + $('#crudTable tbody tr').each(function (i, tr) { const actionCell = $(tr).find('td').eq(actionColumnIndex); + const actionButtons = actionCell.find('a.btn.btn-link'); if(actionCell.find('.actions-buttons-column').length) return; + if(actionButtons.length < minimumThreshold) return; // Wrap the cell with the component needed for the dropdown actionCell.wrapInner('
'); actionCell.wrapInner(''); // Prepare buttons as dropdown items - actionCell.find('a.btn.btn-link').each((index, action) => { + actionButtons.each((index, action) => { $(action).addClass('dropdown-item').removeClass('btn btn-sm btn-link'); $(action).find('i').addClass('me-2 text-primary'); }); diff --git a/src/resources/views/crud/list.blade.php b/src/resources/views/crud/list.blade.php index b16e0869e5..21f5c2855b 100644 --- a/src/resources/views/crud/list.blade.php +++ b/src/resources/views/crud/list.blade.php @@ -60,6 +60,7 @@ class="{{ backpack_theme_config('classes.table') ?? 'table table-striped table-h data-has-details-row="{{ (int) $crud->getOperationSetting('detailsRow') }}" data-has-bulk-actions="{{ (int) $crud->getOperationSetting('bulkActions') }}" data-has-line-buttons-as-dropdown="{{ (int) $crud->getOperationSetting('lineButtonsAsDropdown') }}" + data-line-buttons-as-dropdown-threshold="{{ (int) $crud->getOperationSetting('lineButtonsAsDropdownThreshold') }}" cellspacing="0">