Gridview Filter Column DropDownlist Selection gets cleared

Hi guys,

since I spend most of my time on the IRC channel on freenode, but I could not manage to find an answer I will post it here.

I seem to have encountered a problem regarding the input filter for my gridview. I want to apply custom CSS per filter column so I need the filter property on my column. I tested it with normal array, so I can select values using a dropdownlist. This works like I want, since the value I’ve selected remains after selection, so I can refine my selection further by specifying other values in different columns. But I want to apply a certain CSS class to my filter input, so i tried the following:

 'filter' => CHtml::DropDownList('Log[priority]', '', 

   array('info' => 'info', 'warn' => 'warn', 'error' => 'error', 'fatal' => 'fatal', 'debug' => 'debug'),

   array('class' =>'span2', 'prompt' => '- Priority -')),

This method applies the CSS and show the dropdownlist BUT I lose my selection after selecting my value (for example debug should remain after being selected). I noticed that the selected="selected" is not set anymore on the option item.

Then I tried to put the code in there literally (see below), since it is the same code that worked. It showed the same behavior as the dropdownlist. I checked the code for dropdownlist and the jquery gridview but I had no luck finding the issue.

Is this normal behavior? Anybody any clues?

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

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

 'filter' => $model,

 'itemsCssClass' => 'table table-striped table-bordered table-condensed span11',

 'pagerCssClass' => 'pagination pagination-centered pagination-yii',

 'enableSorting' => true,

 'cssFile' => false,

 'enablePagination' => true,

 'summaryText' => 'Resultaten {start}-{end} van {count} totaal.',

 'columns' => array(


    'header' => 'Server',

    'name' => 'host_id',

    'value' => '$data->host_id',

    'sortable' => TRUE,

    'htmlOptions' => array('nowrap' => 'true', 'width' => '8%'),

    'filter' => CHtml::textField('Log[host_id]', '', array('class' => 'span2')),



    'header' => 'Niveau',

    'name' => 'priority',

    'value' => '$data->priority',

    'sortable' => TRUE,

    'htmlOptions' => array('nowrap' => 'true', 'width' => '8%'),


    'filter' => array('info' => 'info', 'warn' => 'warn', 'error' => 'error','fatal' => 'fatal', 'debug' => 'debug'),

    // WORKS + CSS BUT selection does not remain

    //'filter' => CHtml::DropDownList('Log[priority]', '', 

    //  array('info' => 'info', 'warn' => 'warn', 'error' => 'error', 'fatal' => 'fatal', 'debug' => 'debug'),

    //  array('class' =>'span2', 'prompt' => '- Priority -')),

    // WORKS + CSS BUT selection does not remain 

    /*'filter' => '<select name="Log[priority]" class="span2">

                     <option value=""></option>

                     <option value="info">info</option>

                     <option value="warn">warn</option>

                     <option value="error">error</option>

                     <option value="fatal">fatal</option>

                     <option value="debug">debug</option>




kind regards,


  • Bump *

Hi Robbie,

I solved creating a "base model" like this:

class BaseModel extends CActiveRecord {

  public function getSiNo() {

      return array(

          array('id' => 'Y', 'val' => 'Si'),

          array('id' => 'N', 'val' => 'No'),



  public function getSelectedSiNo($val) {

      if ($val == 'Y')

        return 'Si';

      return 'No';



So I can use the functions everywhere… then I changed every model in order to extend from my new "base model":

class Xyz extends BaseModel




then in my grid view









        'name' => 'ANN_BOX',


        'filter'=>CHtml::listData($model->getSiNo(), 'id', 'val'),



        'name' => 'ANN_BOX_2',


        'filter'=>CHtml::listData($model->getSiNo(), 'id', 'val'),