Question

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?

No correct solution

OTHER TIPS

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/

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top