Skip to content

Commit

Permalink
Merge pull request nextras#72 from milo/pull-fix-filters
Browse files Browse the repository at this point in the history
fixed empty filter values comparison
  • Loading branch information
hrach authored Mar 15, 2017
2 parents b96199f + 4268226 commit 03b1839
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,7 @@ private function prepareFilterDefaults(Container $container)
}

$value = $control->getValue();
$isNonEmptyValue =
(is_array($value) && !empty($value))
|| (is_string($value) && strlen($value) > 0)
|| (!is_array($value) && !is_string($value) && $value !== null);
if ($isNonEmptyValue) {
if (!self::isEmptyValue($value)) {
$this->filterDefaults[$name] = $value;
}
}
Expand All @@ -587,12 +583,18 @@ private function prepareFilterDefaults(Container $container)
private function filterFormFilter(array $values)
{
$filtered = [];
foreach ($values as $key => $val) {
$default = isset($this->filterDefaults[$key]) ? $this->filterDefaults[$key] : null;
if ($default !== $val) {
$filtered[$key] = $val;
foreach ($values as $key => $value) {
$isDefaultDifferent = isset($this->filterDefaults[$key]) && $this->filterDefaults[$key] !== $value;
if ($isDefaultDifferent || !self::isEmptyValue($value)) {
$filtered[$key] = $value;
}
}
return $filtered;
}


private static function isEmptyValue($value)
{
return $value === NULL || $value === '' || $value === [];
}
}

0 comments on commit 03b1839

Please sign in to comment.