Yii2 advanced grid

The extension provides different columns for yii\grid\GridView widget. You can see it on this page.

There is a GridView demo below.

Showing 31-40 of 50 items.
IDName + slugPriceOld PricePriceIs ActiveQuantityReserved
31Product #31
product-31
10000 ↑ 2122%
100
33%
32Product #32
product-32
1323 ↓ -96%
100
92%
33Product #33
product-33
11221 ↑ 5510%
100
60%
34Product #34
product-34
343 ↓ -73%
100
24%
35Product #35
product-35
123 ↓ -98%
100
41%
36Product #36
product-36
12322 ↓ -65%
100
31%
37Product #37
product-37
123444 ↓ -58%
100
33%
38Product #38
product-38
383822 ↑ 293%
100
72%
39Product #39
product-39
39392121 ↑ 1695643%
100
62%
40Product #40
product-40
40704545 ↑ 40704445%
100
93%

DifferenceColumn

The column allows to show a current value and difference between it and last value.

Parameters

  • attribute string the attribute name associated with this column
  • template string|callable the string output template or the render callable
  • difference string|callable the difference attribute name or the calculation callable
  • differenceInPercents bool whether to show difference in percents
  • another fields of yii\grid\DataColumn

Example

[
    'class' =>\yiister\grid\widgets\DifferenceColumn::className(),
    'attribute' => 'price',
    'difference' => function ($model, $column) {
        return $model->price - $model->old_price;
    },
    'differenceInPercents' => true,
    'template' => '{value} <sup class="label label-info">{difference}%</sup>',
],

InputColumn

The column allows to update value via ajax.

Parameters

  • attribute string the attribute name associated with this column
  • updateAction array|string the update action route. See ColumnUpdateAction
  • size string the input size
  • another fields of yii\grid\DataColumn

Example

[
    'class' => \yiister\grid\widgets\InputColumn::className(),
    'attribute' => 'price',
    'updateAction' => '/projects/column-update',
],

MultifieldColumn

The column allows to show some fields in one column by template.

Parameters

  • attribute string the attribute name associated with this column
  • attributes string[] the secondary attribute names array
  • template string|callable the string output template or the render callable
  • another fields of yii\grid\DataColumn

Example

[
    'class' => \yiister\grid\widgets\MultifieldColumn::className(),
    'attribute' => 'name',
    'label' => 'Name + slug',
    'attributes' => ['slug'],
    'template' => '{name}<br /><small><code>{slug}</code></small>',
],

ProgressColumn

The column allows to show a progressbar for associated attribute value.

Parameters

  • attribute string the attribute name associated with this column
  • percent bool whether to show a percents instead of an attribute value
  • minValue int the minimum attribute value
  • maxValue int the maximum attribute value
  • showText bool whether to show the text
  • size string the progress bar size
  • progressBarClass string|callback the progress bar class
  • isStriped bool whether to stripe the progress bar
  • isAnimated bool whether to animate the progress bar
  • another fields of yii\grid\DataColumn

Example

[
    'class' => \yiister\grid\widgets\ProgressColumn::className(),
    'attribute' => 'reserved',
    'size' => \yiister\grid\widgets\ProgressColumn::SIZE_LARGE,
    'isStriped' => true,
    'progressBarClass' => function ($model, $column) {
        return $model->{$column->attribute} > 15
            ? \yiister\grid\widgets\ProgressColumn::STYLE_SUCCESS
            : \yiister\grid\widgets\ProgressColumn::STYLE_WARNING;
    },
],

ToggleColumn

The column allows to show toggle buttons with ability to change value via ajax request.

Parameters

  • attribute string the attribute name associated with this column
  • buttons array of values to rendering
    Data format:
    [
        'value_one' => 'The first label',
        'value_two' => 'The second label',
    ]
  • updateAction array|string the update action route. See ColumnUpdateAction
  • another fields of yii\grid\DataColumn

Example

[
    'class' => \yiister\grid\widgets\ToggleColumn::className(),
    'attribute' => 'is_active',
    'updateAction' => '/projects/column-update',
],

ColumnUpdateAction

The action for column updating. It is used in ajax requests of some columns.

Parameters

  • allowedAttributes array of allowed classes with attributes in the next format
    [
       'app\models\Page' => ['is_active'],
       'app\models\OrderStatus' => ['is_system', 'is_active', 'sort_order'],
    ]

Example

public function actions()
{
    return [
        'column-update' => [
            'class' => ColumnUpdateAction::className(),
            'allowedAttributes' => [
                'app\models\DemoProduct' => ['price', 'old_price', 'is_active'],
            ],
        ],
    ];
}