[Solved] Cgridview With Combined Dropdown And Textfield Filter

I’m facing the problem that the CGridView doesn’t gets refreshed if a value from a dropdown filter is selected after a textfield filter was set.

I have created a minimalistic example for demonstration (see attachment), here is the code:


<?php

   class Entity extends CFormModel {

      public $dropdown_fiter;

      public $text_filter;

		

      public function data() {

         $entities = array();

         $dataprovider = new CArrayDataProvider($entities);

         return $dataprovider;

      }

}

$model = new Entity();

?>


<?php

   $this->widget('zii.widgets.grid.CGridView', array(

      'id' => '-grid',

      'dataProvider' => $model->data(),

      'filter' => $model,

      'columns' => array(

         array(

               'name' => 'dropdown_fiter',

               'value' => 'GxHtml::valueEx($data->dropdown_fiter)',

               'filter' => array('a', 'b', 'c'),

               ),

         'text_filter',

      ),

   ));

?>

It is a simple table with no data. There is a dropdown filter in the first column and a text filter in the second column. The filter input isn’t kept after filtering because of the CArrayDataProvider but that’s irrelevant here.

Now if you select a value from the dropdown you can see that the data gets refreshed by the spinning loading indicator. Same if you input something in the text filter of the second column and press enter.

The problem is the combination of both:

[list=1]

[*]Input some string in the text filter of column two

[*]Select an item in the dropdown of the first column

[/list]

–> The table is not refreshing. In the example you can see it because no loading indicator appears. When you select another dropdown item this works the second time.

Is this a known issue, or am I doing something wrong? I have this problem in my production code which uses a common CActiveDataProvider and CActiveRecord. But I guess this is more JS related which I’m not very familiar with. The script console doesn’t show any errors as there isn’t a AJAX call executed.

I’ve just realized that this problem only occurs in Firefox and IE. In Chrome this is working as expected. Any idea how this can be fixed in Firefox and IE?

I found another question about this in this forum: Cgridview Filters Triggers Only Once When Using Enter Key (Firefox)

There is also a filed bug on github about this with the comments I could fix this problem for me.