Skip to content

Commit

Permalink
Merge pull request #5382 from Laravel-Backpack/action-cell-as-dropdown
Browse files Browse the repository at this point in the history
[BugFix] CRUD table action cell should encapsulate buttons only once
  • Loading branch information
pxpm authored Nov 26, 2023
2 parents 05f813e + d1c7bac commit db12052
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/resources/views/crud/inc/datatables_logic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,21 +403,23 @@ function resizeCrudTableColumnWidths() {
function formatActionColumnAsDropdown() {
// Get action column
const actionColumnIndex = $('#crudTable').find('th[data-action-column=true]').index();
if (actionColumnIndex !== -1) {
$('#crudTable tr').each(function (i, tr) {
const actionCell = $(tr).find('td').eq(actionColumnIndex);
const actionButtons = $(actionCell).find('a.btn.btn-link');
// Wrap the cell with the component needed for the dropdown
actionCell.wrapInner('<div class="nav-item dropdown"></div>');
actionCell.wrapInner('<div class="dropdown-menu dropdown-menu-left"></div>');
// Prepare buttons as dropdown items
actionButtons.map((index, action) => {
$(action).addClass('dropdown-item').removeClass('btn btn-sm btn-link');
$(action).find('i').addClass('me-2 text-primary');
});
actionCell.prepend('<a class="btn btn-sm px-2 py-1 btn-outline-primary dropdown-toggle actions-buttons-column" href="#" data-toggle="dropdown" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">{{ trans('backpack::crud.actions') }}</a>');
if (actionColumnIndex === -1) return;
$('#crudTable tbody tr').each(function (i, tr) {
const actionCell = $(tr).find('td').eq(actionColumnIndex);
if(actionCell.find('.actions-buttons-column').length) return;
// Wrap the cell with the component needed for the dropdown
actionCell.wrapInner('<div class="nav-item dropdown"></div>');
actionCell.wrapInner('<div class="dropdown-menu dropdown-menu-left"></div>');
// Prepare buttons as dropdown items
actionCell.find('a.btn.btn-link').each((index, action) => {
$(action).addClass('dropdown-item').removeClass('btn btn-sm btn-link');
$(action).find('i').addClass('me-2 text-primary');
});
}
actionCell.prepend('<a class="btn btn-sm px-2 py-1 btn-outline-primary dropdown-toggle actions-buttons-column" href="#" data-toggle="dropdown" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">{{ trans('backpack::crud.actions') }}</a>');
});
}
</script>

Expand Down

0 comments on commit db12052

Please sign in to comment.