From 6f220b19542ebc33539d6531d513c7d576eecf21 Mon Sep 17 00:00:00 2001 From: Claudio Pennati Date: Wed, 2 Feb 2022 10:40:50 +0100 Subject: [PATCH] fix select rows query when selectAll --- src/Traits/WithBulkActions.php | 4 ++-- tests/DataTableComponentTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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()); + } }