Is it possible to configure CListView / pager to append results to the current result set, i.e by clicking on a "show more results" button?
Is it possible to configure CListView / pager to append results to the current result set, i.e by clicking on a "show more results" button?
Anybody got any ideas for this?
Dear Friend
This is what I have done. It definetly needs some fine tuning.
Let us have a Model Student.
StudentController
public function actionIndex($more=false)
{
$dataProvider=new CActiveDataProvider('Student',array(
'pagination'=>array('pageSize'=>5),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'more'=>$more
));
}
index.php
<h1>Students</h1>
<?php echo CHtml::button('Show More',array('id'=>'more'));?> <!--Showin the button to get more items.-->
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>$more?"_full":"_partial", //choosing 2 views....
'id'=>'student_list',
)); ?>
<?php
Yii::app()->clientScript->registerScript('more','
$("body").on("click","#more",function(){
$.fn.yiiListView.update("student_list",{data:{more:true}});
});
');
_partial.php
<?php
if($index<1) {?> <!--choosing only the first item in the list-->
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('age')); ?>:</b>
<?php echo CHtml::encode($data->age); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('sex')); ?>:</b>
<?php echo CHtml::encode($data->sex); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('place')); ?>:</b>
<?php echo CHtml::encode($data->place); ?>
<br />
</div>
<?php } ?>
_full.php
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('age')); ?>:</b>
<?php echo CHtml::encode($data->age); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('sex')); ?>:</b>
<?php echo CHtml::encode($data->sex); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('place')); ?>:</b>
<?php echo CHtml::encode($data->place); ?>
<br />
</div>
<?php unset($_GET['more']);?> <!--unset this parameter to get the button working across all pages.-->