Column Summary
PowerGrid can include data summaries inside each columns() header.
Summaries can display the column's sum, count, average, min and max value.
Usage
Summaries are chained to the Column::add()
method.
withSum
- Will display the sum of all records in the field
Parameter | Description | Default |
---|---|---|
(string) $label | The argument $label sets the button caption. | 'Sum' |
(bool) $header | If is true , Powergrid will create a row in the table below the filters. | false |
(bool) $footer | If is true , Powergrid will create a row in the footer of the table. | false |
WARNING
This will pre-process all the data in your database to work with the sum of all records. ->get(), in all cases, only one request is made;
Example:
php
//...
Column::make(__('Price'), 'price')
->withSum('Sum', true, false),
//...
Column::make(__('Price'), 'price')
->withSum('Sum', true, false),
Result:
withCount
- Will display the count of all records in the field
Parameter | Description | Default |
---|---|---|
(string) $label | The argument $label sets the button caption. | 'Count' |
(bool) $header | If is true , Powergrid will create a row in the table below the filters. | false |
(bool) $footer | If is true , Powergrid will create a row in the footer of the table. | false |
Example:
php
//...
Column::make(__('Price'), 'price')
->withCount('Count', true, false),
//...
Column::make(__('Price'), 'price')
->withCount('Count', true, false),
Result:
withAvg
- Will display the avg of all records in the field
Parameter | Description | Default |
---|---|---|
(string) $label | The argument $label sets the button caption. | 'Avg' |
(bool) $header | If is true , Powergrid will create a row in the table below the filters. | false |
(bool) $footer | If is true , Powergrid will create a row in the footer of the table. | false |
Example:
php
//...
Column::make(__('Price'), 'price')
->withAvg('Avg', true, false),
//...
Column::make(__('Price'), 'price')
->withAvg('Avg', true, false),
Result:
withMin
- Will display the min of all records in the field
Parameter | Description | Default |
---|---|---|
(string) $label | The argument $label sets the button caption. | 'Min' |
(bool) $header | If is true , Powergrid will create a row in the table below the filters. | false |
(bool) $footer | If is true , Powergrid will create a row in the footer of the table. | false |
Example:
php
//...
Column::make(__('Price'), 'price')
->withMin('Min', true, false),
//...
Column::make(__('Price'), 'price')
->withMin('Min', true, false),
Result:
withMax
- Will display the max of all records in the field
Parameter | Description | Default |
---|---|---|
(string) $label | The argument $label sets the button caption. | 'Max' |
(bool) $header | If is true , Powergrid will create a row in the table below the filters. | false |
(bool) $footer | If is true , Powergrid will create a row in the footer of the table. | false |
Example:
php
//...
Column::make(__('Price'), 'price')
->withMax('Max', true, false),
//...
Column::make(__('Price'), 'price')
->withMax('Max', true, false),
Result:
Summarizing formatted data
PowerGrid provides a convenient way to use summarizeFormat()
method to display formatted data in your table.
To summarize formatted data (e.g. currency), you must add the passing summaryFormat method that returns an array of key and value (field, Closure).
Ex:
php
public function summarizeFormat(): array
{
return [
'price.{sum,avg}' => function ($value) {
return (new \NumberFormatter('en_US', \NumberFormatter::CURRENCY))
->formatCurrency($value, 'USD');
},
'price.{count,min,max}' => fn ($value) => $value,
];
}
public function summarizeFormat(): array
{
return [
'price.{sum,avg}' => function ($value) {
return (new \NumberFormatter('en_US', \NumberFormatter::CURRENCY))
->formatCurrency($value, 'USD');
},
'price.{count,min,max}' => fn ($value) => $value,
];
}