Yii Framework Forum: CListView ajax pagination and widget working at ajaxLink - Yii Framework Forum

Jump to content

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

CListView ajax pagination and widget working at ajaxLink Rate Topic: ***** 1 Votes

#1 User is offline   cioxideru 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 24-February 12
  • Location:Russia, Bryansk

Posted 06 March 2012 - 02:13 AM

i have simple widget like this:

<?php $id = unique(); ?>
<div id="widget_id_prefix_"<?php echo $id; ?>">
<?php
echo CHtml::ajaxLink(

					Yii::t('site','Add to favorite'),
					array('/default/favorite.ajax'),
					array(
						'type' => 'POST',
						'replace' => '#widget_id_prefix_' . $id,
						'dataType' => 'html',
						'data'=>array(
							'fav_uid'=>$this->fav_uid,
							'action'=>'add',
						)
					)
					,array(
						'id'=>'fw_link'.$id
					)
				);


Next step, i use this widget on render my CDetailView widget like this
template: _favorites.php

$this->widget('zii.widgets.CDetailView', array(
    'data' => $data,
    'attributes' => array(
        array(
            'label' => 'Favorite',
            'type'=>'raw',
            'value'=> $this->widget('FavoriteLinkWidget', array(...),true),
        ),
    ),
));


and it's all repeated by CListView with default ajax pagination like this

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_favorites',
));


at last, code from my controller

if(Yii::app()->request->isAjaxRequest)
            $this->renderPartial('index', compact('dataProvider'),false, true);
        else
            $this->render('index', compact('dataProvider'));


at first page it works fine, but when i click on next page, ajaxLink stops working.
maybe it's not working because of the scripts are loaded at the wrong time?
0

#2 User is offline   Cody 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 02-April 12

Posted 02 April 2012 - 02:33 PM

Did you find any solution?
0

#3 User is offline   cioxideru 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 24-February 12
  • Location:Russia, Bryansk

Posted 20 April 2012 - 08:39 AM

View PostCody, on 02 April 2012 - 02:33 PM, said:

Did you find any solution?

ugly solution.
your can use CHtml::link instead of CHtml::ajaxLink like this

CHtml::link(
	Yii::t('site','Hide talk'),
	Yii::app()->createUrl('#'), array(
		'onclick' => CHtml::ajax(array(
			'url' => Yii::app()->createUrl('/user/message/removetalk'),
			'replace' => '#'.$id,
			'type' => 'GET',
			'dataType' => 'html',
			'data'=>array(
				'id'=>$data->primaryKey,
			)
		)) . 'return false;'
	)
)

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