0

Is it possible to paginate a gridview by month? I'm guessing I can achieve this via ActiveDataProvider by adding a criteria and creating navigations to generate the results per month. But is there an easy way or something built-in in Yii already?

JohnnyQ
  • 4,839
  • 6
  • 47
  • 65

2 Answers2

0

Pagination works by the number of results returned. Maybe group by clause in the query would be the best way to do this.

Also this topic might be of help to you. How to group items by date in Yii CListView?

and this:

http://www.yiiframework.com/forum/index.php/topic/39202-cgridview-datas-group-by-months/

Community
  • 1
  • 1
Jonnny
  • 4,939
  • 11
  • 63
  • 93
0

This will likely be done in the Dataprovider pagination section or using CPagination. The example given

function actionIndex(){
$criteria=new CDbCriteria();
$count=Article::model()->count($criteria);
$pages=new CPagination($count);

// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Article::model()->findAll($criteria);

$this->render('index', array(
'models' => $models,
     'pages' => $pages
));

}

Herer are the available properties

  1. currentPage
  2. itemCount
  3. limit
  4. offset
  5. pageCount
  6. pageSize
  7. pageVar
  8. params
  9. route
  10. validateCurrentPage

You can manually set the pageCount as 12 or check you have data for each month first before passing the correct value.

Your best bet is to then look at pageSize and see if there is anyway of passing this an array of values (ie a count for each month)

I have been unable to find anything more sufficient on this which is suprising as it seems fairly logical someone else has attempted this.

Maybe try posting on the Yii forum as I have had good success there previously.

Please see the following link for the above information.

http://www.yiiframework.com/doc/api/1.1/CPagination

Update

http://www.yiiframework.com/forum/index.php/topic/42936-solved-custom-page-size-for-cgridview-error/

http://www.ramirezcobos.com/2010/11/30/custom-page-size-for-cgridview/

The Humble Rat
  • 4,586
  • 6
  • 39
  • 73
  • Thanks for the tip on Pagination. I actually posted a topic on Yii forums but no one has responded yet. I'll take a look at what I can do with the info you have given. – JohnnyQ Feb 13 '14 at 15:51
  • @JohnnyQ I have added an update to my answer with a couple more links that may be of some use. Solution is different but it seems some of the principles may apply – The Humble Rat Feb 13 '14 at 16:02