diff --git a/src/Concerns/Filter.php b/src/Concerns/Filter.php index ea48d9399..bfc851949 100644 --- a/src/Concerns/Filter.php +++ b/src/Concerns/Filter.php @@ -23,6 +23,23 @@ public function clearFilter(string $field = '', bool $emit = true): void { collect($this->filters()) ->each(function ($filter) use ($field) { + /** + * Filter Number will generate FIELD_start and FIELD_end fields, + * and both fields should also be cleaned. + * Here we verify if there are filter numbers and their fields. + */ + + $extraFieldsToClear = []; + + if (!empty($this->filters['number'])) { + $numberField = str($field)->beforeLast('_start')->beforeLast('_end')->append('')->toString(); + + if (isset($this->filters['number'][$numberField])) { + $field = $numberField; + $extraFieldsToClear = [$numberField . '_start', $numberField . '_end']; + } + } + if (isset($this->filters['multi_select'][$field])) { $this->dispatch('pg:clear_multi_select::' . $this->tableName . ':' . $field); } @@ -55,6 +72,10 @@ public function clearFilter(string $field = '', bool $emit = true): void if ($field === data_get($filter, 'field')) { $unset($filter, $field, null); + + foreach ($extraFieldsToClear as $fieldToClear) { + $unset($filter, $fieldToClear, null); + } }; }); @@ -383,16 +404,19 @@ protected function powerGridQueryString(string $prefix = ''): array } if ($filter->key === 'number') { - $_start = $as->append('_start')->toString(); - $_end = $as->append('_end')->toString(); + $_start = $as->append('_start')->toString(); + $_end = $as->append('_end')->toString(); + $fieldProcessed = false; $queryString['filters.number.' . $filter->field . '.start'] = [ 'as' => $_start, 'except' => '', ]; - if (!is_null(request()->get($_start))) { + if ($fieldProcessed === false && !is_null(request()->get($_start))) { $this->addEnabledFilters($filter->field . '_start', strval($columns->get($filter->field, $filter->field))); + + $fieldProcessed = true; } $queryString['filters.number.' . $filter->field . '.end'] = [ @@ -400,8 +424,10 @@ protected function powerGridQueryString(string $prefix = ''): array 'except' => '', ]; - if (!is_null(request()->get($_end))) { + if ($fieldProcessed === false && !is_null(request()->get($_end))) { $this->addEnabledFilters($filter->field . '_end', strval($columns->get($filter->field, $filter->field))); + + $fieldProcessed = true; } continue; diff --git a/src/Concerns/ToggleDetail.php b/src/Concerns/ToggleDetail.php index 170cf101f..f6e086050 100644 --- a/src/Concerns/ToggleDetail.php +++ b/src/Concerns/ToggleDetail.php @@ -46,7 +46,7 @@ public function toggleDetail(string $id): void /** @var \Illuminate\Support\Enumerable<(int|string), (int|string)> $except */ $except = $id; collect($detailStates)->except($except) - ->filter(fn ($state) => $state)->keys() + ->filter(fn ($state) => boolval($state))->keys() ->each( fn ($key) => data_set($this->setUp, "detail.state.$key", false) ); diff --git a/src/Traits/ExportableJob.php b/src/Traits/ExportableJob.php index 61ec38687..19653e8c7 100644 --- a/src/Traits/ExportableJob.php +++ b/src/Traits/ExportableJob.php @@ -46,7 +46,7 @@ private function prepareToExport(array $properties = []): Eloquent\Collection|Co $sortField = Str::of($processDataSource->component->sortField)->contains('.') ? $processDataSource->component->sortField : $currentTable . '.' . $processDataSource->component->sortField; - $results = $processDataSource->prepareDataSource() + $results = $processDataSource->prepareDataSource() // @phpstan-ignore-line ->where( fn ($query) => Builder::make($query, $this->componentTable) ->filterContains()