Using Ejuicombobox For Cgridview Filtering

Hi.

Has anyone ever tried using a EJuiComboBox to perform CGridView filtering?

I just tried something like this in a CGridView column definition:


array(

  'name'=>'attr',

  'type'=>'raw',

  'filter'=>$this->widget("ext.combobox.EJuiComboBox",array('model'=>$model,'attribute'=>'attr')),

),



It returns no error but the column has no filtering header…

I have to dig it a little more, but in case someone else did the same please share your solution!

thanks!

Make the widget to return the value instead of printing directly:


array(

  'name'=>'attr',

  'type'=>'raw',

  'filter'=>$this->widget("ext.combobox.EJuiComboBox",array('model'=>$model,'attribute'=>'attr'), true),

),

3rd parameter to true

indeed that works, thanks!

at least it displays the combobox, but that doesn’t mean it works :smiley:

I have to check out more what’s going on.

thanks so far!

For benefit of others here’s the full solution.

Install combobox extension.

First patch your combobox javascript with this.

In the CGridView column definition add the widget:




        array(

            'name'=>'column_name',

            'filter'=>$this->widget('ext.combobox.EJuiComboBox', array(

                    'model' => $model,

                    'attribute' => 'attributeName',

                    'data' => CHtml::listData(YourModel::model()->findAll(),'id','description'),

                    'options' => array(

                    'allowText' => false,

                ),

                'assoc'=>true,

            ),true),



Since on the CGridView update the javascript is lost we need to reinstall ComboBox on every change.

So in the CGridView options, before ‘columns’, add:


'afterAjaxUpdate' => 'reinstallComboBox',

then later on on the view:


<?php Yii::app()->clientScript->registerScript('re-install-combobox', "

function reinstallComboBox(id, data) {

    jQuery('#YourModel_attributeName_combobox').combobox({'allowText':false});

}

"); ?>



Replace YourModel with your model name, attributeName with the attribute name you’re trying to filter.