Skip to content

Commit

Permalink
Merge pull request #2751 from feistiny/shift_ID_filter
Browse files Browse the repository at this point in the history
[fix]#2737 Shift the default ID filter,exclude the ID filter later added.
  • Loading branch information
z-song committed Dec 13, 2018
2 parents 777a368 + 009df7e commit 4cd4e4a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Grid/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,22 @@ public function disableIdFilter()
public function removeIDFilterIfNeeded()
{
if (!$this->useIdFilter && !$this->idFilterRemoved) {
$this->removeFilterByID($this->primaryKey);
$this->removeDefaultIDFilter();

foreach ($this->layout->columns() as $column) {
$column->removeFilterByID($this->primaryKey);
}
$this->layout->removeDefaultIDFilter();

$this->idFilterRemoved = true;
}
}

/**
* Remove the default ID filter.
*/
protected function removeDefaultIDFilter()
{
array_shift($this->filters);
}

/**
* Remove filter by filter id.
*
Expand Down Expand Up @@ -469,10 +475,10 @@ public function render()
}

return view($this->view)->with([
'action' => $this->action ?: $this->urlWithoutFilters(),
'layout' => $this->layout,
'filterID' => $this->filterID,
'expand' => $this->expand,
'action' => $this->action ?: $this->urlWithoutFilters(),
'layout' => $this->layout,
'filterID' => $this->filterID,
'expand' => $this->expand,
])->render();
}

Expand Down
12 changes: 12 additions & 0 deletions src/Grid/Filter/Layout/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public function columns()

return $this->columns;
}

/**
* Remove the default ID filter of the default(first) column.
*/
public function removeDefaultIDFilter()
{
$this->columns()
->first()
->filters()
->shift()
;
}
}

0 comments on commit 4cd4e4a

Please sign in to comment.