This extension uses the infinite scroll jQuery plugin, from http://www.infinite-scroll.com/ to create an infinite scrolling pagination, like in twitter. This kind of pagination is also called Endless Scroll.
It uses javascript to load and parse the new pages, but gracefully degrade in cases where javascript is disabled and the users will still be able to access all the pages.
Yii 1.1.4
The YiinfiniteScroller class extends the CBasePager class, so you will use it the same way as CLinkPager and CListPager.
On your controller you need to create the CPagination class which controls the pages handling:
class PostController extends Controller { public function actionIndex() { $criteria = new CDbCriteria; $total = Post::model()->count(); $pages = new CPagination($total); $pages->pageSize = 20; $pages->applyLimit($criteria); $posts = Post::model()->findAll($criteria); $this->render('index', array( 'posts' => $posts, 'pages' => $pages, )); } }
Now on your view you will use it as a widget, like in the following sample:
$this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array( 'itemSelector' => 'div.post', 'pages' => $pages, ));
Note that this will only output the necessary code to the pager. It will not render the page items. Since YiinfiniteScroller extends CBasePager, everything works exactly the same way as if you were using the CListPager or CLinkPager. So, you're need to manually render the items.
In this example, the items are stored in the $posts variable. In our view, we can render the posts by using a simple foreach loop, like in the example bellow:
foreach($posts as $post): <div class="post"> <p>Autor: <?php echo $post->author; </p> <p><?php echo $post->text; </p> </div> <?php endforeach;
This is how the complete view file will look like:
<div id="posts"> <?php foreach($posts as $post): <div class="post"> <p>Autor: <?php echo $post->author; </p> <p><?php echo $post->text; </p> </div> <?php endforeach; </div> <?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array( 'contentSelector' => '#posts', 'itemSelector' => 'div.post', 'loadingText' => 'Loading...', 'donetext' => 'This is the end... my only friend, the end', 'pages' => $pages, ));
There are a few properties that can be set for YiinfiniteScroller:
Total 19 comments
Thanks for this great plugin . Could you please let me know for example if we have 20 pages , display the scrolling up to 10 pages and then showing show more button. For example if you look at facebook wall or alubums , facebook only scrolls you for 10 times and then shows load more button .. I couldn't find that option or am I missing any option ..
Thanks for your help again
Regards Yii Fan
it's very simple with mansory. i just tell use pagination and insert in view:
And he does the rest of the job.
thank you
hi, thank you for this extension, it's works great. I have a pro lem with integrating with http://masonry.desandro.com/demos/infinite-scroll.html
The Masonry has great way to arrange the boxes... do you have a solution?
thank you
Wow,
poor me... I already read this extension several times, but i really dont what the purpose of this extension, and finally when see the demo, i surprise, "this is the extension that I looking for month...."
Thank you davi_alexandre, thank you community.. I really need this extension to show the tree of all of Chart of Account (Accounting apps) in partial way to cut loading times...
Thanks, it works perfectly.
Hi, I want to add function callback with jQuery masonry like the codes below:
How can you do that?
Thanks in advance.
I didn't understand the problem you're facing. Can you give me more details and show me the code on how you're using the extension?
Data printing 3 times from the table... what was th
all data showing when rendering...... below showing next button
Hi, very nice extension! Just a tipp: I needed html options for the infinite_navigation links to hide these links from Google. Just add in the class header
and in the function that creates the navigation
Thanks alot Jule from Hamburg
can someone please help me how can I use it with CListView widget
that's exactly what i was looking for. works fine, thanks for the examples! i just had to change the "$(..." in your YiinfiniteScroller class to "jQuery(.." that's the more popular way. thumbs up. jule
Looks like a great addition, just what I'm needing right now. Cheers!
keep up the good work pal!
Description updated with more detailed examples of how to render the items. :)
How did I render the items in view with this widget?
Can anyone post a sample code?
Thanks!
You render the items on the page yourself, use a loop or a CListView for example. This will make a call back to the page with the next page in the query string. Take the contents of the items on that page and insert it into the current page.
I still dont get it... How do I set how to render each item?
Leave a comment
Please login to leave your comment.