Yii GridView Ajax 刷新
Yii GridView Ajax 刷新,当页面点击一个按钮时,刷新数据。
1.控制器
<?php class privController extends Controller{ public function actionAssign(){ $model=new PrivAssign('search'); $model->unsetAttributes(); if(isset($_GET['PrivAssign'])) $model->attributes=$_GET['PrivAssign']; $this->render('assign',array( 'model'=>$model )); } } ?>
2.视图中
<?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'priv-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'groups', 'modules', 'controller', 'action', 'description', array( 'class'=>'CButtonColumn', ), ), )); ?> <button onclick="refresh()">刷新</button> <script> function refresh(){ $.fn.yiiGridView.update('priv-grid', { type:'POST', url:'<?php echo Yii::app()->createUrl('priv/assign')?>', success:function(data) { $.fn.yiiGridView.update('priv-grid'); } }) } </script>