Append instead of replace items in CListView when using pager

Hi all:

I’m using CListView widget to render by items.

But now when I change the page using pagers provided by CListView, it change the data in the _view.

I’d like to know if I can obtain the old data (says, page 1) and append the new data (page 2) to it so that I can see both data from page 1 and page 2.

Thanks!

I’m not sure if this is doable with the basic Yii pager, but don’t you think that you are about to defeat the purpose of pagers? Anyway, if your project really need such uniqueness, I think you just need to create your own pagers or page links. Say, the first link will render the first 10 results, the second link the first 20, and so on.

Thanks for reply, and I think you’re right about that I’m defeating the purpose of pagers.

However I asked the same question in stack overflow, and someone told me this extension:

yiinfinite-scroll

I tried that extension but it can’t scroll infinite automatically.

Here’s my code:

Controller:




	public function actionScroll()

	{

		$criteria = new CDbCriteria;

		$total = Post::model()->count();


		$pages = new CPagination($total);

		$pages->pageSize = 50;

		$pages->applyLimit($criteria);

		

		$posts = Post::model()->findAll($criteria);


		$this->render('scroll', array(

			'posts' => $posts,

			'pages' => $pages,

		));

	}



View:





<div id="content">

<div id="posts">

<?php

	foreach($posts as $post)

	{

		echo '<div class="post">';

		echo '<p>'.$post->title.'</p>';

		echo '</div>';

	}

?>

</div>

</div>


<?php

$this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(

    'itemSelector' => 'div.post',

    'loadingText' => 'loading..',

    'pages' => $pages,

));

?>




Any idea? thanks!

Yep, I totally agree that yiinfinite-scroll is what you need, unfortunately my previous projects didn’t require such features so I’m not familiar with it.

All I can say is try the latest version available (via SVN), 'cause that usually solves my problem with extensions. Good luck with your project!

You might also find this helpful.