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