@@ -401,26 +401,40 @@ function resizeCrudTableColumnWidths() {
401401 @endif
402402
403403 });
404-
404+
405405 function formatActionColumnAsDropdown () {
406406 // Get action column
407407 const actionColumnIndex = $ (' #crudTable' ).find (' th[data-action-column=true]' ).index ();
408408 if (actionColumnIndex === - 1 ) return ;
409409
410+ const minimumButtonsToBuildDropdown = $ (' #crudTable' ).data (' line-buttons-as-dropdown-minimum' );
411+ const buttonsToShowBeforeDropdown = $ (' #crudTable' ).data (' line-buttons-as-dropdown-show-before-dropdown' );
412+
410413 $ (' #crudTable tbody tr' ).each (function (i , tr ) {
411414 const actionCell = $ (tr).find (' td' ).eq (actionColumnIndex);
412- if (actionCell .find (' .actions-buttons-column' ).length ) return ;
415+ const actionButtons = actionCell .find (' a.btn.btn-link' );
416+ if (actionCell .find (' .actions-buttons-column' ).length ) return ;
417+ if (actionButtons .length < minimumButtonsToBuildDropdown) return ;
413418
414- // Wrap the cell with the component needed for the dropdown
415- actionCell .wrapInner (' <div class="nav-item dropdown"></div>' );
416- actionCell .wrapInner (' <div class="dropdown-menu dropdown-menu-left"></div>' );
417-
418419 // Prepare buttons as dropdown items
419- actionCell . find ( ' a.btn.btn-link ' ). each ((index , action ) => {
420+ const dropdownItems = actionButtons . slice (buttonsToShowBeforeDropdown). map ((index , action ) => {
420421 $ (action).addClass (' dropdown-item' ).removeClass (' btn btn-sm btn-link' );
421422 $ (action).find (' i' ).addClass (' me-2 text-primary' );
423+ return action;
422424 });
423- 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>' );
425+
426+ // Only create dropdown if there are items to drop
427+ if (dropdownItems .length > 0 ) {
428+ // Wrap the cell with the component needed for the dropdown
429+ actionCell .wrapInner (' <div class="nav-item dropdown"></div>' );
430+ actionCell .wrapInner (' <div class="dropdown-menu dropdown-menu-left"></div>' );
431+
432+ 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>' );
433+
434+ // Move the remaining buttons outside the dropdown
435+ const remainingButtons = actionButtons .slice (0 , buttonsToShowBeforeDropdown);
436+ actionCell .prepend (remainingButtons);
437+ }
424438 });
425439 }
426440 </script >
0 commit comments