Hanihh
Hanihh

Reputation: 305

yii cgridview update depending on dropdownlist

I'm newbie with Yii. I have a CGridview with a cutom dataprovider which takes a parameter $select:

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'beneficiary-grid',
'dataProvider' => $model->searchForVoucherAssignment($select),
'filter' => $model,
'columns' => array(
            'id',
    'registration_code',
    'ar_name',
            'en_name',
            'family_member',
            'main_income_source',
            'combine_household',
            array( 'class'=>'CCheckBoxColumn', 'value'=>'$data->id', 'selectableRows'=> '2', 'header' => 'check', 
            ),
),
));

That parameter $select takes its values from dropdownlist:

$data = CHtml::listData(Distribution::model()->findAll(array("condition"=>"status_id =  2")), 'id', 'code');
$select = key($data);
echo CHtml::dropDownList(
    'distribution_id',
    $select,            // selected item from the $data
    $data,       
    array(
    )
);

So I defined a script to update the CGridview depending on the value of dropdownlist

Yii::app()->clientScript->registerScript('sel_status', "
        $('#selStatus').change(function() {
            $.fn.yiiGridView.update('beneficiary-grid', {
                    data: $(this).serialize()
            });            
            return false;
        });
    ");

My model:

public function searchForVoucherAssignment ($distribution_id = 0) {
            $criteria = new CDbCriteria;
            if ($distribution_id != 0) {
                $criteria->condition = "Custom Query...!!";
            }
            $criteria->compare('id', $this->id);

            //Custom Criteria

             return new CActiveDataProvider($this, array(
                'criteria' => $criteria,
                'pagination' => array(
                                    'pageSize' => 20,
                                ),
            ));
        }

The problem is that the CGridview isn't changing where a value of the dropdownlist changed...

Upvotes: 0

Views: 368

Answers (1)

Let me see
Let me see

Reputation: 5094

I think you have selected the wrong Id for the change event. The Id should be

$('#distribution_id').change(function() {

Upvotes: 1

Related Questions