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
$ php composer.phar require chrisb34/reportgrid "@dev"
```
or add:
```php
"chrisb34/yii2-report-grid": "@dev"
```
to the require section of your composer.json file. Then run:
```php
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[...]
Usage
```php
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** : array | boolean, with the following options;
- - if set to true, then reportGrid uses the attribute value, summing the model->attribute or model->value amounts.
- - **value** : string|attribute name|closure ~ function($model, $key, $index, $widget, $break) {}, the value used by the totalling function as opposed to the value displayed.
- - **breakValue** : string|attribute name|closure ~ function($model, $key, $index, $widget, $break) {}, what to display in the sub-total cell. note the addition of the $break variable which can be used to determine the current break level.
For example: you may use if ($break!=1) return $model->some_amount; else return ' ';
- - **showOnBreak** | **hideOnBreak** : integer, show/hide the sub-total at the specified break level
- - **format** : boolean, uses the yii2 formatter to pre-format the cell contents eg: currency, html, text
- - **totalMethod** : the only available option at this stage is ReportColumn::TOTAL_BREAKDOWN, This will provide a summary table at the control break of this column values and summed values specified by totalOn.
- - **totalOn** : string|attribute name|closure ~ function($model, $key, $index, $widget, $break) { return $model->attribute; },, the value to be applied to the totalling.
Usage
```php
'subTotal' => [
'breakValue' => function($model, $key, $index, $widget, $break) {[...]
```
for more info see: [yii2.chris-backhousepercipero.com](http://yii2.
chris-backhouse.com "yii2.chris-backhousepercipero.com/report-grid/home "yii2.percipero.com")