Reputation: 3588
Working under the Yii framework, I have a page that loads and lists different sections. This is, of course, done with renderPartial
a few different views. One of the sections takes an array and displays a list of the items in it. What I need to do is have pagination only for this section, preferably using AJAX so I don't reload all the content upon page selection.
That's the first part of the problem. I've looked into using CActiveDataProvider
with CListView
, however, the problem there is that I'm displaying information from an array that's unrelated to the database. In other words, there's no conditions and so on to create the array, I just have a bunch of $items
and that's about it. Any tips appreciated!
Upvotes: 0
Views: 415
Reputation: 14860
You can use a CArrayDataProvider
instance as the dataProvider
for the CListView
. It has inbuilt pagination support though you may have to explicitly set the pagination's currentPage
.
Upvotes: 2
Reputation: 8072
You can use CLinkPager without CGridView, there is an example:
In controller:
$criteria = new CDbCriteria;
$criteria -> order = 'date';
$pages = new CPagination(Posts::model() -> count());
$pages -> pageSize = 50;
$pages -> applyLimit($criteria);
$posts= Posts::model() -> findAll($criteria);
$this -> controller -> render('list', array('posts' => $posts, 'pages' => $pages));
In view:
<?php $this->widget('CLinkPager',array('pages'=>$pages, "cssFile" => false)); ?>
<ul>
<?php foreach($posts as $x => $post): ?>
<li><?php echo $post -> title ?></li>
<?php endforeach; ?>
</ul>
<?php $this->widget('CLinkPager',array('pages'=>$pages, "cssFile" => false)); ?>
Upvotes: 1