Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search filtering relations and clear filters #8477

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/Forms/GridField/GridFieldFilterHeader.php
Expand Up @@ -154,7 +154,7 @@ public function getActions($gridField)
* If the GridField has a filterable datalist, return an array of actions
*
* @param GridField $gridField
* @return array
* @return void
*/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
Expand All @@ -163,14 +163,13 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
}

$state = $gridField->State->GridFieldFilterHeader;
$state->Columns = null;
if ($actionName === 'filter') {
if (isset($data['filter'][$gridField->getName()])) {
foreach ($data['filter'][$gridField->getName()] as $key => $filter) {
$state->Columns->$key = $filter;
}
}
} elseif ($actionName === 'reset') {
$state->Columns = null;
}
}

Expand All @@ -193,12 +192,10 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList)

$filterArguments = $columns->toArray();
$dataListClone = clone($dataList);
foreach ($filterArguments as $columnName => $value) {
if ($dataList->canFilterBy($columnName) && $value) {
$dataListClone = $dataListClone->filter($columnName . ':PartialMatch', $value);
}
}
return $dataListClone;
$results = $this->getSearchContext($gridField)
->getQuery($filterArguments, false, false, $dataListClone);

return $results;
}

/**
Expand Down Expand Up @@ -337,9 +334,11 @@ public function getSearchForm(GridField $gridField)
$field->addExtraClass('stacked');
}

$name = $gridField->Title ?: singleton($gridField->getModelClass())->i18n_plural_name();

$this->searchForm = $form = new Form(
$gridField,
"SearchForm",
$name . "SearchForm",
$searchFields,
new FieldList()
);
Expand Down