Browse files

BUG GridFieldFilterHeader works without non-filterable cols

Previously relied on the presence of a last column which wasn't filterable,
commonly a GridFieldEditButton. If this wasn't present, the filter buttons
were never added, leading to the GridField JS reload request being sent
without the required button form action, so GridFieldFilterHeader->handleAction()
was never called.
  • Loading branch information...
1 parent 2e2c922 commit c85c495848554af639144ab9f667de02d72bff7c @chillu chillu committed May 23, 2013
Showing with 20 additions and 21 deletions.
  1. +20 −21 forms/gridfield/GridFieldFilterHeader.php
View
41 forms/gridfield/GridFieldFilterHeader.php
@@ -113,7 +113,7 @@ public function getHTMLFragments($gridField) {
$currentColumn++;
$metadata = $gridField->getColumnMetadata($columnField);
$title = $metadata['title'];
-
+ $fields = new FieldGroup();
if($title && $gridField->getList()->canFilterBy($columnField)) {
$value = '';
@@ -127,34 +127,33 @@ public function getHTMLFragments($gridField) {
$field->setAttribute('placeholder',
_t('GridField.FilterBy', "Filter by ") . _t('GridField.'.$metadata['title'], $metadata['title']));
- $field = new FieldGroup(
- $field,
+ $fields->push($field);
+ $fields->push(
GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
->addExtraClass('ss-gridfield-button-reset')
->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)
+ );
+ }
+ if($currentColumn == count($columns)){
+ $fields->push(
+ GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
+ ->addExtraClass('ss-gridfield-button-filter')
+ ->setAttribute('title', _t('GridField.Filter', "Filter"))
+ ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField)
);
- } else {
- if($currentColumn == count($columns)){
- $field = new FieldGroup(
- GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
- ->addExtraClass('ss-gridfield-button-filter')
- ->setAttribute('title', _t('GridField.Filter', "Filter"))
- ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField),
- GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
- ->addExtraClass('ss-gridfield-button-close')
- ->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
- ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)
- );
- $field->addExtraClass('filter-buttons');
- $field->addExtraClass('no-change-track');
- }else{
- $field = new LiteralField('', '');
- }
+ $fields->push(
+ GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
+ ->addExtraClass('ss-gridfield-button-close')
+ ->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
+ ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)
+ );
+ $fields->addExtraClass('filter-buttons');
+ $fields->addExtraClass('no-change-track');
}
- $forTemplate->Fields->push($field);
+ $forTemplate->Fields->push($fields);
}
return array(

0 comments on commit c85c495

Please sign in to comment.