Skip to content

Commit

Permalink
Merge pull request #49 from lelinhtinh/master
Browse files Browse the repository at this point in the history
Trigger the search
  • Loading branch information
n1crack authored Aug 4, 2019
2 parents f443075 + 4751172 commit 6b2dd87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
13 changes: 10 additions & 3 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class Column
*/
public $hidden = false;

/**
* Column seachable
*
* @var bool
*/
public $forceSearch = false;

/**
* Callback function
*
Expand Down Expand Up @@ -72,12 +79,12 @@ public function value($row): string
/**
* Set visibility of the column.
*/
public function hide(): void
public function hide($searchable = false): void
{
$this->hidden = true;
$this->forceSearch = $searchable;
}


/**
* @return bool
*/
Expand Down Expand Up @@ -115,6 +122,6 @@ public function data(): string
*/
public function searchValue(): string
{
return $this->attr['search']['value'];
return $this->attr['search']['value'] ?? '';
}
}
13 changes: 3 additions & 10 deletions src/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,12 @@ public function getQuery(): Query
}

/**
* @param array $columns
* @param string $column
* @return Datatables
*/
public function hide(...$columns): Datatables
public function hide(string $column, $searchable = false): Datatables
{
foreach ($columns as $column) {
if (\is_array($column)) {
$this->hide(...$column);
} else {
$this->columns->getByName($column)->hide();
}
}

$this->columns->getByName($column)->hide($searchable);
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/GlobalSearchableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class GlobalSearchableColumns extends FilterIterator
*/
public function accept(): bool
{
return !$this->current()->hidden && $this->current()->isSearchable();
return ($this->current()->forceSearch || (!$this->current()->hidden && $this->current()->isSearchable()));
}
}

0 comments on commit 6b2dd87

Please sign in to comment.