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

查看:268
本文介绍了如何使用CGridView的Yii中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网址。网格的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的源代码,看看如何<一href="https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridView.php#L394">pagination和<一href="https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CDataColumn.php#L110">sorting从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对象,并CSort对象 $ dataProvider中,有点像这样的:

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.

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

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