From 5ad8fe5f45afab3dbc08e331e69f8e73a13d5f05 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 13 Oct 2013 19:56:12 +0200 Subject: [PATCH] Filter only active attributes in gridview When we do not want an attribute to be searched we do not define it in the filter model, or mark it inctive in the scenario when we use the original model. GridView should not try to access the attribute then and automatically not display the filter field. --- framework/yii/grid/DataColumn.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index 9e0ec79..478394b 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -115,7 +115,9 @@ class DataColumn extends Column { if (is_string($this->filter)) { return $this->filter; - } elseif ($this->filter !== false && $this->grid->filterModel instanceof Model && $this->attribute !== null) { + } elseif ($this->filter !== false && $this->grid->filterModel instanceof Model && + $this->attribute !== null && $this->grid->filterModel->isAttributeActive($this->attribute)) + { if (is_array($this->filter)) { $options = array_merge(array('prompt' => ''), $this->filterInputOptions); return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, $options);