我是Yii的新手。我有一個下拉列表和一個CGridView。這個想法是,我想根據用戶在下拉列表中選擇的內容來過濾gridview中顯示的記錄。我讀過幾篇教程,幾乎所有的教程都很像this one。fn.yiiGridView.update事件不發射
不幸的是,代碼似乎並沒有觸發gridview更新事件。
這裏是根據教程我的代碼
控制器
public function actionIndex()
{
$criteria = (isset($_GET['id-dropdown'])) ?
array(
'condition' => 'account = ' . $_GET['id-dropdown'],
): array();
$options = array(
'criteria' =>$criteria,
'pagination' => array(
'pagesize' => 100,
),
);
$modelAccount = new Account();
$dataProvider = new CActiveDataProvider('Jurnal', $options);
$selected_account = (isset($_GET['id-dropdown'])) ? $_GET['id-dropdown']: '101'; //101 is the default
$this->render('index', array(
//'modelCustom'=>$modelCustom,
'modelAccount'=>$modelAccount,
'dataProvider'=>$dataProvider,
'selected_account' => $selected_account));
}
這是我的看法
<?php
Yii::app()->clientScript->registerScript('items_update', "$('#id-dropdown').change(function(){
alert('ok'); //this works
$.fn.yiiGridView.update('jurnal-grid', {
type:'GET',
data: $(this).serialize(),
success=>
js:function() { $.fn.yiiGridView.update('jurnal-grid');}
}
}
);
});
return false;",
CClientScript::POS_READY);
?>
<h1>View Per Account</h1>
<div class="form">
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'menu-dropdown-form',
'enableAjaxValidation'=>true,
));
echo $form->labelEx($modelAccount, $selected_account);
$criteria = new CDbCriteria();
$criteria->order = 'id ASC';
$account = Account::model()->findAll($criteria);
$accountlist = CHtml::listData($account, 'id', 'description');
echo CHtml::dropDownList('id-dropdown', '$selected_account', $accountlist);
$this->endWidget();
?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'jurnal-grid',
'dataProvider'=>$dataProvider,
'columns' => array(
'tanggal',
'account',
array(
'class' => 'CButtonColumn',
),
),
));
?>
請幫幫我,謝謝你提前
我覺得你在這裏的js'成功=> JS有錯誤:函數(){$ .fn.yiiGridView。更新('jurnal-grid');} }' – ineersa