Skip to content

Commit 428c35d

Browse files
Merge pull request #66 from eduardoribeirodev/2.x
fix: table search functionality in Board
2 parents 81fabb3 + 29f9602 commit 428c35d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/BoardResourcePage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Filament\Actions\Exceptions\ActionNotResolvableException;
1010
use Filament\Forms\Contracts\HasForms;
1111
use Filament\Resources\Pages\Page;
12+
use Livewire\Attributes\Url;
1213
use Relaticle\Flowforge\Concerns\BaseBoard;
1314
use Relaticle\Flowforge\Contracts\HasBoard;
1415

@@ -25,6 +26,9 @@ abstract class BoardResourcePage extends Page implements HasActions, HasBoard, H
2526
{
2627
use BaseBoard;
2728

29+
#[Url(as: 'search')]
30+
public $tableSearch = '';
31+
2832
protected string $view = 'flowforge::filament.pages.board-page';
2933

3034
/**
@@ -43,7 +47,7 @@ abstract class BoardResourcePage extends Page implements HasActions, HasBoard, H
4347
*
4448
* @throws ActionNotResolvableException
4549
*/
46-
protected function resolveActions(array $actions): array
50+
protected function resolveActions(array $actions, bool $isMounting = true): array
4751
{
4852
$resolvedActions = [];
4953

src/Concerns/CanSearchBoardRecords.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ trait CanSearchBoardRecords
1818
/**
1919
* Make the board searchable.
2020
*/
21-
public function searchable(array | Closure $fields = []): static
21+
public function searchable(string | array | Closure $fields = []): static
2222
{
23-
$this->searchableFields = $this->evaluate($fields);
23+
// Ensure fields is an array
24+
$searchableFields = is_string($fields) ? [$fields] : $fields;
25+
26+
$this->searchableFields = $this->evaluate($searchableFields);
2427
$this->isSearchable = true;
2528

2629
return $this;

src/Concerns/HasBoardRecords.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function getBoardRecords(string $columnId): Collection
8181
$queryClone = (clone $baseQuery)->where($statusField, $columnId);
8282
}
8383

84+
// Apply search
85+
if ($livewire->hasTableSearch()) {
86+
$queryClone->where(function ($q) use (&$livewire) {
87+
return $q->whereAny($this->getSearchableFields(), 'LIKE', '%' . $livewire->getTableSearch() . '%');
88+
});
89+
}
90+
8491
$positionField = $this->getPositionIdentifierAttribute();
8592

8693
if ($positionField && $this->modelHasColumn($queryClone->getModel(), $positionField)) {

0 commit comments

Comments
 (0)