@@ -401,30 +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 minimumThreshold = $ (' #crudTable' ).data (' line-buttons-as-dropdown-threshold' );
410+ const minimumToDrop = $ (' #crudTable' ).data (' line-buttons-as-dropdown-minimum-to-drop' );
411+ const dropAfter = $ (' #crudTable' ).data (' line-buttons-as-dropdown-drop-after' );
411412
412413 $ (' #crudTable tbody tr' ).each (function (i , tr ) {
413414 const actionCell = $ (tr).find (' td' ).eq (actionColumnIndex);
414415 const actionButtons = actionCell .find (' a.btn.btn-link' );
415- if (actionCell .find (' .actions-buttons-column' ).length ) return ;
416- if (actionButtons .length < minimumThreshold ) return ;
416+ if (actionCell .find (' .actions-buttons-column' ).length ) return ;
417+ if (actionButtons .length < minimumToDrop ) return ;
417418
418- // Wrap the cell with the component needed for the dropdown
419- actionCell .wrapInner (' <div class="nav-item dropdown"></div>' );
420- actionCell .wrapInner (' <div class="dropdown-menu dropdown-menu-left"></div>' );
421-
422419 // Prepare buttons as dropdown items
423- actionButtons .each ((index , action ) => {
420+ const dropdownItems = actionButtons .slice (dropAfter). map ((index , action ) => {
424421 $ (action).addClass (' dropdown-item' ).removeClass (' btn btn-sm btn-link' );
425422 $ (action).find (' i' ).addClass (' me-2 text-primary' );
423+ return action;
426424 });
427- 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 , dropAfter);
436+ actionCell .prepend (remainingButtons);
437+ }
428438 });
429439 }
430440 </script >
0 commit comments