How do I use the ajaxUrl parameter of CGridView in Yii?

狂风中的少年 提交于 2019-12-19 07:28:08

问题


I'm trying to use ajaxUrl param of CGridView and it's having no effect.

$this->widget('zii.widgets.grid.CGridView', array(
   'id'=>'ge-cg-'.$myLib['id'],
   'filter'=>$geCGModel,
   'dataProvider'=>$dataProvider, 
   'columns'=>$columns,
   'ajaxUrl'=>Yii::app()->createUrl( 'Something/search' ),
));

This doesn't seem to be overriding the ajax url of the CGridView widget. The grid's ajax request is still going to the controller that rendered it (which is different than the grid's own controller).

Thanks!


回答1:


The ajaxUrl property works only for searches, both the "per column filters" and "advanced search". The sort links and pagination links are generated from the $dataProvider that you specify. You can check the source of CGridView and CDataColumn to see how pagination and sorting is extracted from the dataProvider, respectively.

Hence if you want those links to also use the same ajaxUrl that you want to specify, then you have to set the route property for both the CPagination object, and CSort object of the $dataProvider, somewhat like this:

$dataProvider=new CActiveDataProvider('Modelname',array(
    'criteria'=>$criteria,
    'pagination'=>array(
        'route'=>'something/search'
    ),
    'sort'=>array(
        'route'=>'something/search'
    )
));

This combined with your current CGridView settings should work as expected.



来源:https://stackoverflow.com/questions/12626622/how-do-i-use-the-ajaxurl-parameter-of-cgridview-in-yii

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!