我是Yii的新手。
我有一个带有cutom dataprovider的CGridview,它带有参数$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',
            ),
),
));


该参数$selectdropdownlist获取其值:

$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(
    )
);


所以我定义了一个脚本,用于根据dropdownlist的值更新CGridview

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


我的模特:

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,
                                ),
            ));
        }


问题是CGridview不会在dropdownlist的值更改的地方更改...

最佳答案

我认为您为更改事件选择了错误的ID。 Id应该是

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

关于javascript - yii cgridview更新取决于下拉列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24200588/

10-11 12:14