diff --git a/src/Forms/GridField/GridFieldFilterHeader.php b/src/Forms/GridField/GridFieldFilterHeader.php index 6efe105d9..3d5888212 100755 --- a/src/Forms/GridField/GridFieldFilterHeader.php +++ b/src/Forms/GridField/GridFieldFilterHeader.php @@ -176,6 +176,7 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi } $state = $this->getState($gridField); + $state->Columns = []; if ($actionName === 'filter') { if (isset($data['filter'][$gridField->getName()])) { diff --git a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php index 41dd7b725..91e1a14f3 100644 --- a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php +++ b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php @@ -118,4 +118,25 @@ class GridFieldFilterHeaderTest extends SapphireTest $this->assertEquals('place', $searchSchema->filters->Search__City); $this->assertEquals('testfield', $searchSchema->gridfield); } + + public function testHandleActionReset() + { + // Init Grid state with some pre-existing filters + $state = $this->gridField->State; + $state->GridFieldFilterHeader = []; + $state->GridFieldFilterHeader->Columns = []; + $state->GridFieldFilterHeader->Columns->Name = 'test'; + + $this->component->handleAction( + $this->gridField, + 'reset', + [], + '{"GridFieldFilterHeader":{"Columns":{"Name":"test"}}}' + ); + + $this->assertEmpty( + $state->GridFieldFilterHeader->Columns->toArray(), + 'GridFieldFilterHeader::handleAction resets the gridstate filter when the user resets the search.' + ); + } }