From 000e29d328579b8c905ab6c632868b338d383135 Mon Sep 17 00:00:00 2001 From: lelinhtinh Date: Sun, 4 Aug 2019 13:12:14 +0700 Subject: [PATCH 1/3] Trigger the search --- src/Column.php | 16 +++++++++++++++- src/Datatables.php | 17 +++++++++++++++++ src/Iterators/GlobalSearchableColumns.php | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Column.php b/src/Column.php index 83436f9..56b31bb 100644 --- a/src/Column.php +++ b/src/Column.php @@ -23,6 +23,13 @@ class Column */ public $hidden = false; + /** + * Column seachable + * + * @var bool + */ + public $triggerSearch = false; + /** * Callback function * @@ -77,6 +84,13 @@ public function hide(): void $this->hidden = true; } + /** + * Set seachable of the column. + */ + public function triggerSearch(): void + { + $this->triggerSearch = true; + } /** * @return bool @@ -115,6 +129,6 @@ public function data(): string */ public function searchValue(): string { - return $this->attr['search']['value']; + return $this->attr['search']['value'] ?? ''; } } diff --git a/src/Datatables.php b/src/Datatables.php index 68e85f7..67613c7 100644 --- a/src/Datatables.php +++ b/src/Datatables.php @@ -156,6 +156,23 @@ public function hide(...$columns): Datatables return $this; } + /** + * @param array $columns + * @return Datatables + */ + public function triggerSearch(...$columns): Datatables + { + foreach ($columns as $column) { + if (\is_array($column)) { + $this->triggerSearch(...$column); + } else { + $this->columns->getByName($column)->triggerSearch(); + } + } + + return $this; + } + /** * @param string $query * @return Datatables diff --git a/src/Iterators/GlobalSearchableColumns.php b/src/Iterators/GlobalSearchableColumns.php index c2ee4c8..5ebb07b 100644 --- a/src/Iterators/GlobalSearchableColumns.php +++ b/src/Iterators/GlobalSearchableColumns.php @@ -17,6 +17,6 @@ class GlobalSearchableColumns extends FilterIterator */ public function accept(): bool { - return !$this->current()->hidden && $this->current()->isSearchable(); + return ($this->current()->triggerSearch || (!$this->current()->hidden && $this->current()->isSearchable())); } } \ No newline at end of file From 4277379b0f80463b5a815bcf0ea1da91e7de8069 Mon Sep 17 00:00:00 2001 From: lelinhtinh Date: Sun, 4 Aug 2019 18:09:30 +0700 Subject: [PATCH 2/3] Merge into hide method --- src/Column.php | 13 +++---------- src/Datatables.php | 23 +++-------------------- src/Iterators/GlobalSearchableColumns.php | 2 +- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/Column.php b/src/Column.php index 56b31bb..032496b 100644 --- a/src/Column.php +++ b/src/Column.php @@ -28,7 +28,7 @@ class Column * * @var bool */ - public $triggerSearch = false; + public $forceSearch = false; /** * Callback function @@ -79,17 +79,10 @@ public function value($row): string /** * Set visibility of the column. */ - public function hide(): void + public function hide($searchable = false): void { $this->hidden = true; - } - - /** - * Set seachable of the column. - */ - public function triggerSearch(): void - { - $this->triggerSearch = true; + $this->forceSearch = $searchable; } /** diff --git a/src/Datatables.php b/src/Datatables.php index 67613c7..921448a 100644 --- a/src/Datatables.php +++ b/src/Datatables.php @@ -143,30 +143,13 @@ public function getQuery(): Query * @param array $columns * @return Datatables */ - public function hide(...$columns): Datatables + public function hide($searchable = false, ...$columns): Datatables { foreach ($columns as $column) { if (\is_array($column)) { - $this->hide(...$column); + $this->hide($searchable, ...$column); } else { - $this->columns->getByName($column)->hide(); - } - } - - return $this; - } - - /** - * @param array $columns - * @return Datatables - */ - public function triggerSearch(...$columns): Datatables - { - foreach ($columns as $column) { - if (\is_array($column)) { - $this->triggerSearch(...$column); - } else { - $this->columns->getByName($column)->triggerSearch(); + $this->columns->getByName($column)->hide($searchable); } } diff --git a/src/Iterators/GlobalSearchableColumns.php b/src/Iterators/GlobalSearchableColumns.php index 5ebb07b..ca2f59a 100644 --- a/src/Iterators/GlobalSearchableColumns.php +++ b/src/Iterators/GlobalSearchableColumns.php @@ -17,6 +17,6 @@ class GlobalSearchableColumns extends FilterIterator */ public function accept(): bool { - return ($this->current()->triggerSearch || (!$this->current()->hidden && $this->current()->isSearchable())); + return ($this->current()->forceSearch || (!$this->current()->hidden && $this->current()->isSearchable())); } } \ No newline at end of file From 4751172652f67155b1039f972019817cd4f2913f Mon Sep 17 00:00:00 2001 From: lelinhtinh Date: Sun, 4 Aug 2019 18:16:54 +0700 Subject: [PATCH 3/3] Update Datatables --- src/Datatables.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Datatables.php b/src/Datatables.php index 921448a..5865d14 100644 --- a/src/Datatables.php +++ b/src/Datatables.php @@ -140,19 +140,12 @@ public function getQuery(): Query } /** - * @param array $columns + * @param string $column * @return Datatables */ - public function hide($searchable = false, ...$columns): Datatables + public function hide(string $column, $searchable = false): Datatables { - foreach ($columns as $column) { - if (\is_array($column)) { - $this->hide($searchable, ...$column); - } else { - $this->columns->getByName($column)->hide($searchable); - } - } - + $this->columns->getByName($column)->hide($searchable); return $this; }