Yii Framework Forum: CListView and CHtml::button not working together with pagination - Yii Framework Forum

Jump to content

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

CListView and CHtml::button not working together with pagination Rate Topic: -----

#1 User is offline   rhmtts 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 20-December 11

Posted 30 May 2012 - 03:16 AM

Not sure if this is a bug or I'm missing something, but it seems strange to me:

If you put a view in a paginated CListView that has a CHtml::button that leads to an url of some sort in it, the urls are not updated when when the next page is loaded:

<?php $this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'enablePagination' => true,
)); ?>


The _view :

$url = '/something/update/id/' . $data->primaryKey;
<?php echo CHtml::button('Edit', array(
       'submit' => $url,
   )); ?>


The output of this is some javascript:


<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
    jQuery('#yw1').yiiListView({'ajaxUpdate':['yw1'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'list-view-loading','sorterClass':'sorter'});
    $('body').on('click','#yt1',function(){jQuery.yii.submitForm(this,'/something/update/id/62',{});return false;});
    
// ...

    $('body').on('click','#yt10',function(){jQuery.yii.submitForm(this,'/something/update/id/87',{});return false;});
});
/*]]>*/
</script>


And some html that looks like this:

<input name="yt10" type="button" value="Edit" id="yt1" />

<!-- ... -->

<input name="yt10" type="button" value="Edit" id="yt10" />


Which makes perfect sense. HOWEVER, if you click on one of the links in the pagination area, only the HTML for the new items is fetched (using Ajax), NOT the corresponding JavaScript code. As a result, the first button on the new page will open the same link as the first button on the original page (as it has the same id - yt1).

Is there a "correct" way around this? As far as I can tell CListView does not have an option to disable loading new pages using Ajax. All other solutions I can think of involve writing my own Javascript for the buttons, which is doable, of course, but kind of ugly and un-Yii-like.

Also, it seems to me, but again, I might be missing something, that this behavior is in fact a bug - the original Javascript does not get updated when a user clicks a link in the pagination area of the widget
0

#2 User is offline   dieter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 16-September 11
  • Location:Boston, MA

Posted 05 September 2012 - 09:37 AM

View Postrhmtts, on 30 May 2012 - 03:16 AM, said:

Not sure if this is a bug or I'm missing something, but it seems strange to me:

If you put a view in a paginated CListView that has a CHtml::button that leads to an url of some sort in it, the urls are not updated when when the next page is loaded:

...




Hello,

Did you ever find a solution for your problem? Just came across the same issue. As soon as I move to a new page, the buttons stop working based on the missing Java Script for these buttons.

Cheers,
Dieter
0

#3 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 06 September 2012 - 12:38 PM

Friends

It works when the property 'ajaxUpdate' of CListView is set to false.
But the advantage of ajax loading of pages in CListView is lost.

The 'submit' in 'htmlOptions' of CHtml::button method registers a Javascript.
I think this is not available in ajax loaded pages. I am not able to figure it out the exact problem.

CHtml::link method works very well as it does not leave any script in normal usages.

I hope some workaround may be there.
0

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 14 September 2012 - 08:31 AM

A solution is to wrap the view portion you want updated as well in a div with id="something", and specify that something as the value of the ajaxUpdate property.
Edit: an answer that has strictly nothing to do with the issue :)
0

#5 User is offline   rontiki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-March 11

Posted 14 September 2012 - 09:31 AM

CListView and CGridView javascript code for updating the view extract the content of div specified by their 'id' property. In essence, javascript code registered using CClientScript will not be rendered since the code will normally be outside that div.

So you are going to get the old javascript responding to your clicks resulting in the same url.
0

#6 User is offline   sravani_hft 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 20-October 12
  • Location:India

Posted 27 December 2012 - 08:40 AM

Try this

Add to CListView 'ajaxUpdate'=>false,


<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'ajaxUpdate'=>false,
)); ?>
0

#7 User is offline   rajesh chaurasia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 12-January 13
  • Location:Mohali

Posted 30 May 2013 - 02:27 AM

hi friends to hide goto page you can use

$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enablePagination'=>false,
'template'=>"{items}\n{pager}",
));
?>
0

#8 User is offline   greg_gregson 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 04-July 14

Posted 05 July 2014 - 09:09 PM

Has anyone found a nice solution for this problem? None of the above suggestions have worked for me.
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