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 41-50 of 50 items.
IDName + slugPriceOld PricePriceIs ActiveQuantityReserved
41Product #41
product-41
1.2E+40 ↑ 0%
100
77%
42Product #42
product-42
4242333 ↑ 32573%
100
9%
43Product #43
product-43
788774 ↑ 90459%
100
14%
44Product #44
product-44
1.0E+95 ↑ 0%
100
42%
45Product #45
product-45
4333 ↑ 67%
100
69%
46Product #46
product-46
2000 ↑ 63%
100
19%
47Product #47
product-47
4747 ↑ 1089%
100
89%
48Product #48
product-48
1231236 ↑ 26429%
100
86%
49Product #49
product-49
4567 ↑ 81%
100
63%
50Product #50
product-50
8989 ↑ 163%
100
56%

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'],
            ],
        ],
    ];
}