CGridView external filter

Dear All,

Here is a case, I have dropDownList,CJuiAutoComplete and CGridView .

Based on the drop down list , CJuiAutoComplete gets the typed selection from the database and here is the code for it .

<?php echo CHtml::dropDownList('type','',array('Company'=>'Company','Profession'=>'Profession','People'=>'People')); ?>


$this->widget('zii.widgets.jui.CJuiAutoComplete', array(


           'source'=>'js: function(request, response) {


		           url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",

		           dataType: "json",

		           data: {

		               term: request.term,

		               brand: $("#type").val()


		           success: function (data) {





 			 'options' => array(

			                'showAnim' => 'fold',

			                'select' => 'js:function(event, ui){ alert(ui.item.value) }'




This works perfect . And now I want to pass the dropdown list value ( In the above case Company , profession or People) and the selected value from CJuiAutoComplete to CGridView data provider and display the results in CGridView . Again whenever user changes the value in dropdown list or in CJuiAutoComplete I want to refresh CGridView . Could some one please throw me some light how to implement this

( Code snippet passing dropdown list and CJuiAutoComplete values to CGridView data provider whenever there change )

THANKS A LOT FOR YOUR HELP :D :) :lol: :rolleyes:

I’ve done this in the past by placing hidden fields in the filter section of one of the other attributes in the CGridView, and having the external fields set the value of the hidden field to their own value when they’re changed. Then they tell the CGridView to refresh (I think there is a way of doing this directly, but I have always called ‘$("#filter").change()’ on one of the other filters in the CGridView.

So in CGridView you would have:

'columns' => array(


        'name' => 'attribute1'

        'filter' => CHtml::activeTextField($model, "attribute1").CHtml::activeHiddenField($model, "externalAttribute"),


    ... other columns ...


This assumes that your external filter is an attribute in the model that the CGridView is working from. If not you might need to spell the hidden field out rather than use CHtml to do it for you. Also you need to make sure the filter for the column is what you wanted.

Then in the select function of your CJuiAutoComplete you add:

$('#modelName_externalAttribute').val(ui.item.value); $('#modelName_attribute1').change();

replacing modelName with the name of the model.

The rest you should be able to do from the controller end, filtering using externalAttribute.

If you want to send the dropDownList’s value too then you can do the same for that.

Hope this helps.

Sorry for the late response ( was busy with office work and didn’t get time to check my personal work) and Thanks a lot for this solution . I will try this one . :rolleyes: