Hi folks,
I found quite strange behaviour of ClistView. I think it would be best if I’ll show you code which I have and will describe problem at the bottom.
in controller ArtistsController.php I have this code:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('artists', array(
'pagination'=>array(
'pageSize'=>32,
),
'sort'=>false,
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
In index view I have this code:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'template'=>'{sorter}<br />{pager}{items}<br />{pager}', //{summary}
'enableSorting' => false,
'sortableAttributes'=>array(
'name'=>'by name',
),
'pager'=>array(
'class'=>'CLinkPager',
'cssFile'=>$pager_css_location,
'prevPageLabel'=>'<',
'nextPageLabel'=>'>',
),
)); ?>
And in _view.php(item for DataProvider) I have the following AjaxLinks:
$ajax_follow_artist_list = $this->beginWidget('CActiveForm', array(
'id'=>'ajaxfollowartistlist-form',
'enableAjaxValidation'=>false,
'action'=>$followed_artists_form_url,
));
echo CHtml::ajaxLink("Follow",Yii::app()->createUrl('artists/ajaxfollowartistfromlist'),
array( // ajaxOptions
'type' =>'POST',
'success'=>"function(data){
if(data==\"show_dont_track_button\"){
$(\"#dont_track_button$data->id\").show();
$(\"#track_button$data->id\").hide();
}
}",
'data' => array('artist_id'=>$data->id)
),
array( //htmlOptions
'class' => "button small blue",
'id' => 'track_button'.$data->id,
'style'=>$button_style_track_artist,
)
);
echo CHtml::ajaxLink("Not follow",Yii::app()->createUrl('artists/ajaxfollowartistfromlist'),
array( // ajaxOptions
'type' =>'POST',
'success'=>"function(data){
if(data==\"show_track_button\"){
$(\"#dont_track_button$data->id\").hide();
$(\"#track_button$data->id\").show();
}
}",
'data' => array('artist_id'=>$data->id)
),
array( //htmlOptions
'class' => "button small red",
'id' => 'dont_track_button'.$data->id,
'style'=>$button_style_dont_track_artist,
)
);
$this->endWidget();
So the problem. I can see that Yii only publishes Jquery code for first page of elements (34 elements in my case) the rest is not there and when I click on other page jquery code for next 34 elements is not published on the page. So Ajax functionality is not working obviously, has anyone seen this bug before? I am using Yii yii-1.1.5.r2654.
I can see only this Jquery code for first 34 elements(I use Firebug):
jQuery('body').delegate('#track_button1','click',function(){jQuery.ajax({'type':'POST','success':function(data){
if(data=="show_dont_track_button"){
$("#dont_track_button1").show();
$("#track_button1").hide();
}
},'data':{'artist_id':'1'},'url':'/test2/index.php/artists/ajaxfollowartistfromlist','cache':false});return false;});
jQuery('body').delegate('#dont_track_button1','click',function(){jQuery.ajax({'type':'POST','success':function(data){
if(data=="show_track_button"){
$("#dont_track_button1").hide();
$("#track_button1").show();
}
},'data':{'artist_id':'1'},'url':'/test2/index.php/artists/ajaxfollowartistfromlist','cache':false});return false;});
jQuery('body').delegate('#track_button2','click',function(){jQuery.ajax({'type':'POST','success':function(data){
if(data=="show_dont_track_button"){
$("#dont_track_button2").show();
$("#track_button2").hide();