Search code examples
phpyiiwidgetcgridviewjquery-ui-multiselect

Yii echmultiselect not filtering multiselect


i'm having problems with echmultiselect in my project, it doesn't filter at all and inhibits other column filters already working.

View

    array ( 
            'name'=>'typeSelectedName',
            'value'=>'$data->typeSelected->name',
            'filter'=> $this->widget('EchMultiselect', array(
                'model' => $model,
                'dropDownAttribute' => 'typeSelectedName',
                'dropDownHtmlOptions'=> array(
                     'style'=>'width:225px;',
                     'multiple'=>true,
           ),
          'data' => array('A'=>'A','B'=>'B','C'=>'C','Z'=>'Z','X'=>'X','K'=>'K','T'=>'T'),
           'options' => array(
                'header'=> Yii::t('EchMultiSelect.EchMultiSelect',''),
                'buttonWidth' => 80, 
                'position'=>array('my'=>'left bottom', 'at'=>'left top'),
                'ajaxRefresh' => true,  
                'multiselect'=>true,
                'filter'=>true,
           ),
         ),
       true // capture output; needed so the widget displays inside the grid
     ),
   ),

Model

$criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    if(!empty($this->type)) {
       foreach($this->type as $v) {
             $criteria->compare('type', $v, false, 'OR');
                    }
            }
    $criteria->compare('sa_id',$this->sa_id,true);

...

i am using yii 1.1.13 and i can see this Cgridview: enter image description here


Solution

    1. Your dropdown attribute in multyselect is typeSelectedName while in the model file for criteria you check type attribute.
    2. The multyselect makes an ajax call; so you need to check it and what kind of data are passed in it.

    Better you add some options inside multiselect to invoke custom ajax for model filtering: upon returned data do update grid. This way multyselect will be working as the only filter option (no other options will be taken into account); though you might get form data thru this.form.serialize() and make joined filtering.