Problem with CListView and ajaxUrl property

Hello!

I want to use the ajaxUrl property to customize the URL for update CListView’s pages, but this property not work, the requests are made to the current URL, I try to debug it with Firebug and seems CLinkPager widget don’t know which is the ajax URL to use when user click on a page number: the options passed to $.fn.yiiListView.update include the current URL, not the ajaxUrl.

EDIT: My code looks like.

The view:


$this->widget('zii.widgets.CListView',array(

	'dataProvider'=>$lastPosts,

	'itemView'=>'_post',

	'ajaxUrl'=>'site/lastPosts'

));


//... Another widgets with other DataProviders



The site controller:


public function actionLastPosts(){

	$lastPosts = Post::findLastPosts();


	$this->widget('zii.widgets.CListView',array(

		'dataProvider'=>$lastPosts,

		'itemView'=>'_post',

		'ajaxUrl'=>'site/lastPosts'

	));

}

Thanks!!

use createUrl method from Controller to get path your action controller.




'ajaxUrl'=>$this->createUrl('site/lastPosts')



Tried, but still not working :( .

Try




Yii::app()->createUrl('site/lastPosts')

No, this doesn’t work either.

But setting the route to DataProvider’s pagination before calling the widget, works… checking the CListView and related classes code, I notice that Yii use the pagination attribute of the DataProvider and the createPageUrl method of that pagination to generate the URL, but never assign a route to that pagination, then the route is empty => current URL.


$lastPosts->pagination->route = 'site/lastPosts';


$this->widget('zii.widgets.CListView',array(

        'dataProvider'=>$lastPosts,

        'itemView'=>'_post',

        'ajaxUrl'=>'site/lastPosts'

));

This solve my problem.

Is this a bug or am I still using ajaxUrl in a inappropriate way?

Thanks!!

Is this a bug?

Same question here!

Hi all

i also faced with problem that setting ajaxUrl of CGridView does not influence of pagination url!

CPagination is created at the moment when dataprovider and takes current route if no one set manually! And usually we do not set it.

it’s not a bug but non logical: cgridview and pager are to different but binded widgets so they shoud share urls.

The solution is described by eor above: to set the route of pagination manually.

I use this more universal piece of code:




    $dp->pagination->route = $this->id.'/grid';


    $this->widget('CGridView', array(

    'id' => 'my-grid',

    'ajaxUrl' => array($dp->pagination->route), 

    'dataProvider' => $dp,

    ...  



Hope it will be corrected in future versions of yii.

In case anyone wanted to know, since I struggled with this as well, you can assign additional parameters to the URL by:


$dataProvider->getPagination()->params = array("param1" => "val1", "param2" => "val1");

Do note, however, if your application is already calling certain parameters say for a page ID you’ll need to specify it within the params variable again:


$dataProvider->getPagination()->params = array("id" => $model->id, "param1" => "val1");

Finally, you don’t need to specify ajaxUrl with the new route since it’s kind of a dummy variable at this point.

If clistview is displayed using ajax in a separate div tag and clicked on the next button of pager the view gets displayed improperly with layout being changed what could be the problem