Yii Framework Forum: Problem with CListView and ajaxUrl property - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem with CListView and ajaxUrl property Rate Topic: -----

#1 User is offline   eor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-May 11

Posted 23 July 2011 - 11:09 AM

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!!
0

#2 User is offline   Hermans 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 17-February 11

Posted 23 July 2011 - 11:25 AM

use createUrl method from Controller to get path your action controller.
'ajaxUrl'=>$this->createUrl('site/lastPosts')

0

#3 User is offline   eor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-May 11

Posted 23 July 2011 - 12:04 PM

View PostHermans, on 23 July 2011 - 11:25 AM, said:

use createUrl method from Controller to get path your action controller.
'ajaxUrl'=>$this->createUrl('site/lastPosts')



Tried, but still not working :( .
0

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 579
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 23 July 2011 - 12:33 PM

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

Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#5 User is offline   eor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-May 11

Posted 23 July 2011 - 03:52 PM

View PostPeRoChAk, on 23 July 2011 - 12:33 PM, said:

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!!
0

#6 User is offline   eor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-May 11

Posted 25 July 2011 - 08:35 AM

Is this a bug?
0

#7 User is offline   Sebastian K. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 29-May 11

Posted 23 November 2011 - 11:09 AM

View Posteor, on 25 July 2011 - 08:35 AM, said:

Is this a bug?

Same question here!
0

#8 User is offline   Vitalets 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 16-December 11
  • Location:Moscow / Russia

Posted 15 March 2012 - 11:47 AM

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.
have a look on my extensions:
EColumns - show/hide and reorder columns in gridview
GroupGridView - merge cells and make group rows in gridview
SelGridView - keep selection in gridview
0

#9 User is offline   Enom 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-November 12

Posted 07 November 2012 - 11:46 AM

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

#10 User is offline   Ninad 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 04-December 12

Posted 20 February 2013 - 02:46 AM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users