From fd419bb2929785ea9858d7a4e53bb7cb7f197be6 Mon Sep 17 00:00:00 2001 From: RazvanDrelciuc Date: Wed, 24 Sep 2025 14:05:50 +0300 Subject: [PATCH] added option to disable bulk actions on specific records --- resources/js/laravel-livewire-tables.js | 44 +++++++++++-------- resources/js/laravel-livewire-tables.min.js | 2 +- .../table/td/bulk-actions.blade.php | 36 ++++++++------- .../table/th/bulk-actions.blade.php | 4 +- .../BulkActionsConfiguration.php | 7 +++ src/Traits/Helpers/BulkActionsHelpers.php | 29 +++++++++++- src/Traits/WithBulkActions.php | 2 + src/Traits/WithData.php | 28 ++++++++++++ src/Traits/WithPagination.php | 4 ++ 9 files changed, 117 insertions(+), 39 deletions(-) diff --git a/resources/js/laravel-livewire-tables.js b/resources/js/laravel-livewire-tables.js index 532a615ea..f38f9ab6d 100644 --- a/resources/js/laravel-livewire-tables.js +++ b/resources/js/laravel-livewire-tables.js @@ -7,14 +7,17 @@ document.addEventListener('alpine:init', () => { paginationCurrentCount: wire.entangle('paginationCurrentCount'), paginationTotalItemCount: wire.entangle('paginationTotalItemCount'), paginationCurrentItems: wire.entangle('paginationCurrentItems'), + paginationCurrentSelectableItems: wire.entangle('paginationCurrentSelectableItems'), + hasDisabledBulkActionsRows: wire.entangle('hasDisabledBulkActionsRows'), selectedItems: wire.entangle('selected'), alwaysShowBulkActions: !wire.entangle('hideBulkActionsWhenEmpty'), + paginationTotalSelectableItemCount: wire.entangle("paginationTotalSelectableItemCount"), toggleSelectAll() { if (!showBulkActionsAlpine) { return; } - if (this.paginationTotalItemCount === this.selectedItems.length) { + if (this.paginationTotalSelectableItemCount === this.selectedItems.length) { this.clearSelected(); } else { this.setAllSelected(); @@ -39,8 +42,11 @@ document.addEventListener('alpine:init', () => { return; } + console.log('bulk-select 222patched rzv') let tempSelectedItems = this.selectedItems; - const iterator = this.paginationCurrentItems.values(); + const iterator = this.hasDisabledBulkActionsRows + ? this.paginationCurrentSelectableItems + : this.paginationCurrentItems.values(); for (const value of iterator) { tempSelectedItems.push(value.toString()); } @@ -85,7 +91,7 @@ document.addEventListener('alpine:init', () => { updateWire() { let tmpFilterMin = parseInt(this.filterMin); let tmpFilterMax = parseInt(this.filterMax); - + if (tmpFilterMin != this.originalMin || tmpFilterMax != this.originalMax) { if (tmpFilterMax < tmpFilterMin) { this.filterMin = tmpFilterMax; @@ -103,14 +109,14 @@ document.addEventListener('alpine:init', () => { this.wireValues = { 'min': this.filterMin, 'max': this.filterMax }; wire.set('filterComponents.' + filterKey, this.wireValues); } - + }, init() { this.setupWire(); this.$watch('allFilters', value => this.setupWire()); }, })); - + Alpine.data('flatpickrFilter', (wire, filterKey, filterConfig, refLocation, locale) => ({ wireValues: wire.entangle('filterComponents.' + filterKey), flatpickrInstance: flatpickr(refLocation, { @@ -159,8 +165,8 @@ document.addEventListener('alpine:init', () => { this.setupWire(); this.$watch('wireValues', value => this.setupWire()); } - - + + })); Alpine.data('reorderFunction', (wire, tableID, primaryKeyName) => ({ dragging: false, @@ -192,7 +198,7 @@ document.addEventListener('alpine:init', () => { } let target = event.target.closest('tr'); this.currentlyHighlightedElement = target; - + if (event.offsetY < (target.getBoundingClientRect().height / 2)) { target.classList.add('laravel-livewire-tables-highlight-top'); target.classList.remove('laravel-livewire-tables-highlight-bottom'); @@ -209,7 +215,7 @@ document.addEventListener('alpine:init', () => { if (typeof this.currentlyHighlightedElement == 'object') { this.currentlyHighlightedElement.classList.remove('laravel-livewire-tables-highlight-bottom', 'laravel-livewire-tables-highlight-top'); } - + let target = event.target.closest('tr'); let parent = event.target.closest('tr').parentNode; let element = document.getElementById(this.sourceID).closest('tr'); @@ -227,8 +233,8 @@ document.addEventListener('alpine:init', () => { if (newPosition < originalPosition) { loopStart = newPosition; } - - /* + + /* let evenList = parentNode.querySelectorAll("table[tableType='rappasoft-laravel-livewire-tables']>tbody>tr:nth-child(even of tr.rappasoft-striped-row) ").forEach(function (elem) { elem.classList.remove(...this.oddNotInEven); row.classList.add(...this.evenNotInOdd); @@ -253,14 +259,14 @@ document.addEventListener('alpine:init', () => { reorderToggle() { if (this.currentlyReorderingStatus) { wire.disableReordering(); - + } else { if (this.hideReorderColumnUnlessReorderingStatus) { this.reorderDisplayColumn = true; } wire.enableReordering(); - + } }, cancelReorder() { @@ -268,7 +274,7 @@ document.addEventListener('alpine:init', () => { this.reorderDisplayColumn = false; } wire.disableReordering(); - + }, updateOrderedItems() { let table = document.getElementById(tableID); @@ -280,11 +286,11 @@ document.addEventListener('alpine:init', () => { }, setupEvenOddClasses() { if (this.currentlyReorderingStatus === true) { - + let tbody = document.getElementById(tableID).getElementsByTagName('tbody')[0]; let evenRowClassArray = []; let oddRowClassArray = []; - + if (tbody.rows[0] !== undefined && tbody.rows[1] !== undefined) { evenRowClassArray = Array.from(tbody.rows[0].classList); oddRowClassArray = Array.from(tbody.rows[1].classList); @@ -297,8 +303,8 @@ document.addEventListener('alpine:init', () => { }, init() { this.$watch('currentlyReorderingStatus', value => this.setupEvenOddClasses()); - + } })); - -}); \ No newline at end of file + +}); diff --git a/resources/js/laravel-livewire-tables.min.js b/resources/js/laravel-livewire-tables.min.js index 6d78ed178..41289f6cb 100644 --- a/resources/js/laravel-livewire-tables.min.js +++ b/resources/js/laravel-livewire-tables.min.js @@ -1 +1 @@ -document.addEventListener("alpine:init",()=>{Alpine.data("tableWrapper",(e,t)=>({childElementOpen:!1,filtersOpen:e.entangle("filterSlideDownDefaultVisible"),paginationCurrentCount:e.entangle("paginationCurrentCount"),paginationTotalItemCount:e.entangle("paginationTotalItemCount"),paginationCurrentItems:e.entangle("paginationCurrentItems"),selectedItems:e.entangle("selected"),alwaysShowBulkActions:!e.entangle("hideBulkActionsWhenEmpty"),toggleSelectAll(){t&&(this.paginationTotalItemCount===this.selectedItems.length?this.clearSelected():this.setAllSelected())},setAllSelected(){t&&e.setAllSelected()},clearSelected(){t&&e.clearSelected()},selectAllOnPage(){if(!t)return;let e=this.selectedItems,i=this.paginationCurrentItems.values();for(let l of i)e.push(l.toString());this.selectedItems=[...new Set(e)]}})),Alpine.data("numberRangeFilter",(e,t,i,l,a)=>({allFilters:e.entangle("filterComponents",!1),originalMin:0,originalMax:100,filterMin:0,filterMax:100,currentMin:0,currentMax:100,hasUpdate:!1,wireValues:e.entangle("filterComponents."+t,!1),defaultMin:l.minRange,defaultMax:l.maxRange,restrictUpdates:!1,updateStyles(){let e=document.getElementById(i),t=document.getElementById(a+"-min"),l=document.getElementById(a+"-max");e.style.setProperty("--value-a",t.value),e.style.setProperty("--text-value-a",JSON.stringify(t.value)),e.style.setProperty("--value-b",l.value),e.style.setProperty("--text-value-b",JSON.stringify(l.value))},setupWire(){void 0!==this.wireValues?(this.filterMin=this.originalMin=void 0!==this.wireValues.min?this.wireValues.min:this.defaultMin,this.filterMax=this.originalMax=void 0!==this.wireValues.max?this.wireValues.max:this.defaultMax):(this.filterMin=this.originalMin=this.defaultMin,this.filterMax=this.originalMax=this.defaultMax),this.updateStyles()},allowUpdates(){this.updateWire()},updateWire(){let e=parseInt(this.filterMin),t=parseInt(this.filterMax);(e!=this.originalMin||t!=this.originalMax)&&(tthis.setupWire())}})),Alpine.data("flatpickrFilter",(e,t,i,l,a)=>({wireValues:e.entangle("filterComponents."+t),flatpickrInstance:flatpickr(l,{mode:"range",clickOpens:!0,allowInvalidPreload:!0,defaultDate:[],ariaDateFormat:i.ariaDateFormat,allowInput:i.allowInput,altFormat:i.altFormat,altInput:i.altInput,dateFormat:i.dateFormat,locale:"en",minDate:i.earliestDate,maxDate:i.latestDate,onOpen:function(){window.childElementOpen=!0},onChange:function(i,l,a){if(i.length>1){var s=l.split(" ")[0],r=l.split(" ")[2],n={};window.childElementOpen=!1,window.filterPopoverOpen=!1,n={minDate:s,maxDate:r},e.set("filterComponents."+t,n)}}}),setupWire(){if(void 0!==this.wireValues){if(void 0!==this.wireValues.minDate&&void 0!==this.wireValues.maxDate){let e=[this.wireValues.minDate,this.wireValues.maxDate];this.flatpickrInstance.setDate(e)}else this.flatpickrInstance.setDate([])}else this.flatpickrInstance.setDate([])},init(){this.setupWire(),this.$watch("wireValues",e=>this.setupWire())}})),Alpine.data("reorderFunction",(e,t,i)=>({dragging:!1,reorderEnabled:!1,sourceID:"",targetID:"",evenRowClasses:"",oddRowClasses:"",currentlyHighlightedElement:"",evenRowClassArray:{},oddRowClassArray:{},evenNotInOdd:{},oddNotInEven:{},orderedRows:[],defaultReorderColumn:e.get("defaultReorderColumn"),reorderStatus:e.get("reorderStatus"),currentlyReorderingStatus:e.entangle("currentlyReorderingStatus"),hideReorderColumnUnlessReorderingStatus:e.entangle("hideReorderColumnUnlessReorderingStatus"),reorderDisplayColumn:e.entangle("reorderDisplayColumn"),dragStart(e){this.sourceID=e.target.id,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",e.target.id),e.target.classList.add("laravel-livewire-tables-dragging")},dragOverEvent(e){"object"==typeof this.currentlyHighlightedElement&&this.currentlyHighlightedElement.classList.remove("laravel-livewire-tables-highlight-bottom","laravel-livewire-tables-highlight-top");let t=e.target.closest("tr");this.currentlyHighlightedElement=t,e.offsetYi.getBoundingClientRect().height/2?l.insertBefore(a,i.nextSibling):l.insertBefore(a,i),r!l.includes(e)),this.oddNotInEven=l.filter(e=>!i.includes(e)),i=[],l=[])}},init(){this.$watch("currentlyReorderingStatus",e=>this.setupEvenOddClasses())}}))}); \ No newline at end of file +document.addEventListener("alpine:init",(()=>{Alpine.data("tableWrapper",((e,t)=>({childElementOpen:!1,filtersOpen:e.entangle("filterSlideDownDefaultVisible"),paginationCurrentCount:e.entangle("paginationCurrentCount"),paginationTotalItemCount:e.entangle("paginationTotalItemCount"),paginationCurrentItems:e.entangle("paginationCurrentItems"),paginationCurrentSelectableItems:e.entangle("paginationCurrentSelectableItems"),hasDisabledBulkActionsRows:e.entangle("hasDisabledBulkActionsRows"),selectedItems:e.entangle("selected"),alwaysShowBulkActions:!e.entangle("hideBulkActionsWhenEmpty"),paginationTotalSelectableItemCount:e.entangle("paginationTotalSelectableItemCount"),toggleSelectAll(){t&&(this.paginationTotalSelectableItemCount===this.selectedItems.length?this.clearSelected():this.setAllSelected())},setAllSelected(){t&&e.setAllSelected()},clearSelected(){t&&e.clearSelected()},selectAllOnPage(){if(!t)return;console.log("bulk-select 222patched rzv");let e=this.selectedItems;const i=this.hasDisabledBulkActionsRows?this.paginationCurrentSelectableItems:this.paginationCurrentItems.values();for(const t of i)e.push(t.toString());this.selectedItems=[...new Set(e)]}}))),Alpine.data("numberRangeFilter",((e,t,i,l,a)=>({allFilters:e.entangle("filterComponents",!1),originalMin:0,originalMax:100,filterMin:0,filterMax:100,currentMin:0,currentMax:100,hasUpdate:!1,wireValues:e.entangle("filterComponents."+t,!1),defaultMin:l.minRange,defaultMax:l.maxRange,restrictUpdates:!1,updateStyles(){let e=document.getElementById(i),t=document.getElementById(a+"-min"),l=document.getElementById(a+"-max");e.style.setProperty("--value-a",t.value),e.style.setProperty("--text-value-a",JSON.stringify(t.value)),e.style.setProperty("--value-b",l.value),e.style.setProperty("--text-value-b",JSON.stringify(l.value))},setupWire(){void 0!==this.wireValues?(this.filterMin=this.originalMin=void 0!==this.wireValues.min?this.wireValues.min:this.defaultMin,this.filterMax=this.originalMax=void 0!==this.wireValues.max?this.wireValues.max:this.defaultMax):(this.filterMin=this.originalMin=this.defaultMin,this.filterMax=this.originalMax=this.defaultMax),this.updateStyles()},allowUpdates(){this.updateWire()},updateWire(){let e=parseInt(this.filterMin),t=parseInt(this.filterMax);e==this.originalMin&&t==this.originalMax||(tthis.setupWire()))}}))),Alpine.data("flatpickrFilter",((e,t,i,l,a)=>({wireValues:e.entangle("filterComponents."+t),flatpickrInstance:flatpickr(l,{mode:"range",clickOpens:!0,allowInvalidPreload:!0,defaultDate:[],ariaDateFormat:i.ariaDateFormat,allowInput:i.allowInput,altFormat:i.altFormat,altInput:i.altInput,dateFormat:i.dateFormat,locale:"en",minDate:i.earliestDate,maxDate:i.latestDate,onOpen:function(){window.childElementOpen=!0},onChange:function(i,l,a){if(i.length>1){var s,r=l.split(" ")[0],n=l.split(" ")[2];window.childElementOpen=!1,window.filterPopoverOpen=!1,s={minDate:r,maxDate:n},e.set("filterComponents."+t,s)}}}),setupWire(){if(void 0!==this.wireValues)if(void 0!==this.wireValues.minDate&&void 0!==this.wireValues.maxDate){let e=[this.wireValues.minDate,this.wireValues.maxDate];this.flatpickrInstance.setDate(e)}else this.flatpickrInstance.setDate([]);else this.flatpickrInstance.setDate([])},init(){this.setupWire(),this.$watch("wireValues",(e=>this.setupWire()))}}))),Alpine.data("reorderFunction",((e,t,i)=>({dragging:!1,reorderEnabled:!1,sourceID:"",targetID:"",evenRowClasses:"",oddRowClasses:"",currentlyHighlightedElement:"",evenRowClassArray:{},oddRowClassArray:{},evenNotInOdd:{},oddNotInEven:{},orderedRows:[],defaultReorderColumn:e.get("defaultReorderColumn"),reorderStatus:e.get("reorderStatus"),currentlyReorderingStatus:e.entangle("currentlyReorderingStatus"),hideReorderColumnUnlessReorderingStatus:e.entangle("hideReorderColumnUnlessReorderingStatus"),reorderDisplayColumn:e.entangle("reorderDisplayColumn"),dragStart(e){this.sourceID=e.target.id,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",e.target.id),e.target.classList.add("laravel-livewire-tables-dragging")},dragOverEvent(e){"object"==typeof this.currentlyHighlightedElement&&this.currentlyHighlightedElement.classList.remove("laravel-livewire-tables-highlight-bottom","laravel-livewire-tables-highlight-top");let t=e.target.closest("tr");this.currentlyHighlightedElement=t,e.offsetYi.getBoundingClientRect().height/2?l.insertBefore(a,i.nextSibling):l.insertBefore(a,i),r!l.includes(e))),this.oddNotInEven=l.filter((e=>!i.includes(e))),i=[],l=[])}},init(){this.$watch("currentlyReorderingStatus",(e=>this.setupEvenOddClasses()))}})))})); diff --git a/resources/views/components/table/td/bulk-actions.blade.php b/resources/views/components/table/td/bulk-actions.blade.php index f9b4db46b..3d34ca9d8 100644 --- a/resources/views/components/table/td/bulk-actions.blade.php +++ b/resources/views/components/table/td/bulk-actions.blade.php @@ -8,26 +8,30 @@ @endphp @if ($component->bulkActionsAreEnabled() && $component->hasBulkActions()) - +
$theme === 'tailwind', 'form-check' => $theme === 'bootstrap-5', ])> - merge($bulkActionsTdCheckboxAttributes)->class([ - 'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), - 'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), - 'except' => 'default', - ]) - }} - /> + @if ($this->hasBulkSelection($row)) + merge($bulkActionsTdCheckboxAttributes)->class([ + 'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), + 'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), + 'except' => 'default', + ]) + }} + /> + @endif
@endif diff --git a/resources/views/components/table/th/bulk-actions.blade.php b/resources/views/components/table/th/bulk-actions.blade.php index 2d846ff3d..d57f8444c 100644 --- a/resources/views/components/table/th/bulk-actions.blade.php +++ b/resources/views/components/table/th/bulk-actions.blade.php @@ -18,9 +18,9 @@ > merge($bulkActionsThCheckboxAttributes)->class([ 'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsThCheckboxAttributes['default'] ?? true), diff --git a/src/Traits/Configuration/BulkActionsConfiguration.php b/src/Traits/Configuration/BulkActionsConfiguration.php index 813d46f42..1769fe0b0 100644 --- a/src/Traits/Configuration/BulkActionsConfiguration.php +++ b/src/Traits/Configuration/BulkActionsConfiguration.php @@ -150,4 +150,11 @@ public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxA return $this; } + + public function setHasDisabledBulkActionRows(bool $status): self + { + $this->hasDisabledBulkActionsRows = $status; + + return $this; + } } diff --git a/src/Traits/Helpers/BulkActionsHelpers.php b/src/Traits/Helpers/BulkActionsHelpers.php index 29f162bb6..d88db3c52 100644 --- a/src/Traits/Helpers/BulkActionsHelpers.php +++ b/src/Traits/Helpers/BulkActionsHelpers.php @@ -2,6 +2,8 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; +use Illuminate\Database\Eloquent\Model; + trait BulkActionsHelpers { public function getBulkActionsStatus(): bool @@ -145,7 +147,32 @@ public function updatedSelected(): void public function setAllSelected(): void { $this->setSelectAllEnabled(); - $this->setSelected((clone $this->baseQuery())->pluck($this->getBuilder()->getModel()->getTable().'.'.$this->getPrimaryKey())->map(fn ($item) => (string) $item)->toArray()); + + if ($this->hasDisabledBulkSectionRows()) { + $selected = []; + (clone $this->baseQuery()) + ->each(function ($item) use (&$selected) { + if (!$this->hasBulkSelection($item)) { + return; + } + + $selected[] = (string)$item->{$this->getPrimaryKey()}; + $this->setSelected($selected); + }); + } else { + $this->setSelected((clone $this->baseQuery())->pluck($this->getBuilder()->getModel()->getTable() . '.' . $this->getPrimaryKey())->map(fn($item) => (string)$item)->toArray()); + + } + } + + public function hasBulkSelection(Model $model): bool + { + return true; + } + + public function hasDisabledBulkSectionRows(): bool + { + return $this->hasDisabledBulkActionsRows; } public function showBulkActionsDropdownAlpine(): bool diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index e05175733..252eb4644 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -22,6 +22,8 @@ trait WithBulkActions public bool $hideBulkActionsWhenEmpty = false; + public bool $hasDisabledBulkActionsRows = false; + public ?string $bulkActionConfirmDefaultMessage; protected array $bulkActionsCheckboxAttributes = []; diff --git a/src/Traits/WithData.php b/src/Traits/WithData.php index 9dcd44a4c..6fc1f358a 100644 --- a/src/Traits/WithData.php +++ b/src/Traits/WithData.php @@ -38,6 +38,14 @@ public function getRows(): Collection|CursorPaginator|Paginator|LengthAwarePagin // Get All Currently Paginated Items Primary Keys $this->paginationCurrentItems = $executedQuery->pluck($this->getPrimaryKey())->toArray() ?? []; + // Get Currently Selectable Paginated Items Primary Keys + $this->paginationCurrentSelectableItems = $executedQuery + ->filter(function ($row) { + return $this->hasBulkSelection($row); + }) + ->pluck($this->getPrimaryKey()) + ->toArray() ?? []; + // Get Count of Items in Current Page $this->paginationCurrentCount = $executedQuery->count(); @@ -79,6 +87,9 @@ protected function executeQuery(): Collection|CursorPaginator|Paginator|LengthAw // Get the total number of items available $this->paginationTotalItemCount = $paginatedResults->total() ?? 0; + $this->paginationTotalSelectableItemCount = $this->hasDisabledBulkSectionRows() ? + $this->computeTotalSelectableCount() : $this->paginationTotalItemCount; + return $paginatedResults; } @@ -86,6 +97,9 @@ protected function executeQuery(): Collection|CursorPaginator|Paginator|LengthAw $this->paginationTotalItemCount = $this->getBuilder()->count(); + $this->paginationTotalSelectableItemCount = $this->hasDisabledBulkSectionRows() ? + $this->computeTotalSelectableCount() : $this->paginationTotalItemCount; + return $this->getBuilder()->simplePaginate($this->getPerPage() === -1 ? $this->paginationTotalItemCount : $this->getPerPage(), ['*'], $this->getComputedPageName()); } @@ -93,6 +107,8 @@ protected function executeQuery(): Collection|CursorPaginator|Paginator|LengthAw if ($this->isPaginationMethod('cursor')) { $this->paginationTotalItemCount = $this->getBuilder()->count(); + $this->paginationTotalSelectableItemCount = $this->hasDisabledBulkSectionRows() ? + $this->computeTotalSelectableCount() : $this->paginationTotalItemCount; return $this->getBuilder()->cursorPaginate($this->getPerPage() === -1 ? $this->paginationTotalItemCount : $this->getPerPage(), ['*'], $this->getComputedPageName()); } @@ -262,4 +278,16 @@ public function renderingWithData(\Illuminate\View\View $view, array $data = []) 'rows' => $this->getRows(), ]); } + + protected function computeTotalSelectableCount(): int + { + $count = 0; + $this->baseQuery()->each(function ($row) use (&$count) { + if ($this->hasBulkSelection($row)) { + $count++; + } + }); + + return $count; + } } diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 676d034b6..fabf09603 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -31,10 +31,14 @@ trait WithPagination public array $paginationCurrentItems = []; + public array $paginationCurrentSelectableItems = []; + public int $paginationCurrentCount = 0; public ?int $paginationTotalItemCount = null; + public ?int $paginationTotalSelectableItemCount = null; + public array $numberOfPaginatorsRendered = []; protected bool $shouldShowPaginationDetails = true;