Skip to content

Commit 2c855e4

Browse files
authored
fix clearFilter method with dot-notation in field name (#2057)
* fix clearFilter method with dot-notation in field name * small update * make it more readable
1 parent 2acdb0a commit 2c855e4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Concerns/Filter.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public function clearFilter(string $field = ''): void
7272
$explodeField = explode('.', $field);
7373

7474
$currentArray = &$this->filters[$key];
75-
unset($currentArray[$explodeField[0]]);
75+
76+
$this->removeNestedArrayKey($currentArray, $explodeField[0], $explodeField[1]);
7677
}
7778

7879
unset($this->filters[$key][$field]);
@@ -519,4 +520,15 @@ protected function powerGridQueryString(string $prefix = ''): array
519520

520521
return $queryString;
521522
}
523+
524+
private function removeNestedArrayKey(array &$array, string $parent, string $child): void
525+
{
526+
if (isset($array[$parent][$child])) {
527+
unset($array[$parent][$child]);
528+
}
529+
530+
if (isset($array[$parent]) && empty($array[$parent])) {
531+
unset($array[$parent]);
532+
}
533+
}
522534
}

0 commit comments

Comments
 (0)