如何在 Yii 中使用 CGridView 的 ajaxUrl 参数? [英] How do I use the ajaxUrl parameter of CGridView in Yii?

查看:21
本文介绍了如何在 Yii 中使用 CGridView 的 ajaxUrl 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 CGridView 的 ajaxUrl 参数,但没有效果.

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

这似乎没有覆盖 CGridView 小部件的 ajax url.网格的 ajax 请求仍然会发送到呈现它的控制器(这与网格自己的控制器不同).

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).

谢谢!

推荐答案

ajaxUrl 属性仅适用于搜索,包括每列过滤器"和高级搜索".排序链接和分页链接是从您指定的 $dataProvider 生成的.你可以查看 CGridView 和 CDataColumn 的源码,看看 分页排序分别从dataProvider中提取.

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.

因此,如果您希望这些链接也使用您想要指定的相同 ajaxUrl,那么您必须为 CPagination 对象和$dataProvider 的 CSort 对象,有点像这样:

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'
    )
));

结合您当前的 CGridView 设置应该可以按预期工作.

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

这篇关于如何在 Yii 中使用 CGridView 的 ajaxUrl 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆