Skip to content

Commit

Permalink
only validated filter values pass to data source callback [Closes nex…
Browse files Browse the repository at this point in the history
  • Loading branch information
milo committed Mar 31, 2017
1 parent 03b1839 commit 97bbbe0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,22 @@ protected function attached($presenter)
protected function getData($key = null)
{
if (!$this->data) {
$validFilterData = [];
if ($this->filterFormFactory) {
$this['form']->isValid(); // triggers validation
foreach ($this['form']['filter']->controls as $name => $control) {
if ($control->getErrors() === []) {
$validFilterData[$name] = $control->getValue();
}
}
$validFilterData = $this->filterFormFilter($validFilterData);
}

$onlyRow = $key !== null && $this->presenter->isAjax();
if (!$onlyRow && $this->paginator) {
$itemsCount = call_user_func(
$this->paginatorItemsCountCallback,
$this->filterDataSource,
$validFilterData,
$this->orderColumn ? [$this->orderColumn, strtoupper($this->orderType)] : null
);

Expand All @@ -353,7 +364,7 @@ protected function getData($key = null)

$this->data = call_user_func(
$this->dataSourceCallback,
$this->filterDataSource,
$validFilterData,
$this->orderColumn ? [$this->orderColumn, strtoupper($this->orderType)] : null,
$onlyRow ? null : $this->paginator
);
Expand Down

0 comments on commit 97bbbe0

Please sign in to comment.