diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index 6c995ed5d..b8d6192f6 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -68,8 +68,8 @@ public function resetBulk(): void */ public function selectedRowsQuery() { - return $this->query()->unless( - $this->selectAll, + return $this->query()->when($this->selectAll, + fn ($query) => $this->applySearchFilter($query), fn ($query) => $query->whereIn($query->qualifyColumn($this->primaryKey), $this->selected) ); } diff --git a/tests/DataTableComponentTest.php b/tests/DataTableComponentTest.php index 4dfca67b3..5ebc8d239 100644 --- a/tests/DataTableComponentTest.php +++ b/tests/DataTableComponentTest.php @@ -161,4 +161,16 @@ public function bulk_actions_defined_through_function() $this->table->selected[] = 1; $this->assertEquals(1, $this->table->count()); } + + /** @test */ + public function bulk_actions_defined_through_with_select_all_function() + { + $this->assertArrayHasKey('count', $this->table->bulkActions); + + $this->table->resetFilters(); + $this->table->filters['search'] = 'Chico'; + $this->assertEquals(1, $this->table->getRowsProperty()->total()); + $this->table->selectAll(); + $this->assertEquals(1, $this->table->count()); + } }