Difference between #2 and #3 of
Yii2 Report Grid

Revision #3 has been created by CeBe on Mar 25, 2018, 2:04:21 AM with the memo:

update headlines
« previous (#2) next (#4) »


Title unchanged

Yii2 Report Grid

Category unchanged


Yii version changed


Tags changed

GgridVview, report

Content changed

A Yii2 Gridview designed specifically for reporting ------------------===================================================

There are some very advanced grids in the Yii2 community, specifically Kartik's amazing gridview extensions but they all designed for interactive screen use.
But more importantantly it has sub-totalling and report totalling built into the gridview itself.

### Why is this significant
Because it enables you to use closures (anonymous functions) within the sub-total fields. For example, say we want to build a report on order items, with a break at order level. At the order level, we want to report something off the order model but the dataProvider is on the order-item level.

$ php composer.phar require chrisb34/reportgrid "@dev" ``` or add:
"chrisb34/yii2-report-grid": "@dev" ``` to the require section of your composer.json file. Then run:
php composer.phar update ``` to get the updated package on your application install. ### Widget Setup
As with most Yii2 widgets, you control the using options on widget creation. This widget is based on the Yii2 gridview widget, so anything mentioned here is over and above the base options on the gridview widget


echo ReportGrid::widget([
'dataProvider' => $dataProvider,

### Column Configuration
When you use sub-totalling in a report, your report layout must follow the same structure as your query. So the first thing is to define your query with the results in the correct order.


'subTotal' => [
'breakValue' => function($model, $key, $index, $widget, $break) {
if ($break == 1)
return $model->category_name;
elseif ($break == 0)
6 0
Viewed: 20 891 times
Version: 2.0
Category: Tips
Written by: Chris Backhouse
Last updated by: Chris Backhouse
Created on: Jul 11, 2017
Last updated: a year ago
Update Article


View all history