diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/TableComponent.php | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/TableComponent.php b/src/TableComponent.php index 7186b1f..14d631b 100644 --- a/src/TableComponent.php +++ b/src/TableComponent.php @@ -68,7 +68,10 @@ abstract class TableComponent extends Component protected function isSearching(): bool { - $search = $this->getToolbar()?->getSearch(); + $search = $this + ->getToolbars() + ->first(fn(Toolbar $tb) => $tb->getSearch() !== null) + ?->getSearch(); return $search !== null && Str::length($this->search) >= $search->getMinLength(); } @@ -101,19 +104,19 @@ abstract class TableComponent extends Component } } - protected function toolbar(): ?Toolbar + protected function toolbars(): array { - return null; + return []; } - private ?Toolbar $toolbarCache; + private Collection $toolbarsCache; - protected function getToolbar(): ?Toolbar + protected function getToolbars(): Collection { - if (!isset($this->_toolbar)) { - $this->toolbar = $this->toolbar(); + if (!isset($this->toolbarsCache)) { + $this->toolbarsCache = collect($this->toolbars()); } - return $this->toolbar; + return $this->toolbarsCache; } protected function query() : Builder @@ -131,7 +134,9 @@ abstract class TableComponent extends Component protected function getFilters(): Collection { - return $this->getToolbar()?->getFilters() ?? collect(); + return $this->getToolbars() + ->map(fn(Toolbar $toolbar) => $toolbar->getFilters()) + ->flatten(); } @@ -182,12 +187,12 @@ abstract class TableComponent extends Component $data = $this->buildQuery()->paginate($this->pageSize); $allColumns = $this->getColumns(); $columns = $allColumns->filter(fn($c) => in_array($c->name,$this->activeColumns)); - $toolbar = $this->toolbar(); + $toolbars = $this->getToolbars(); Paginator::defaultView('laralight-tables::pagination'); return view('laralight-tables::table', compact( - 'data', 'allColumns', 'columns', 'toolbar', + 'data', 'allColumns', 'columns', 'toolbars', )); } } |