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 1-10 of 50 items.
IDName + slugPriceOld PricePriceIs ActiveQuantityReserved
2Product #2
product-2
↓ -100%
100
86%
7Product #7
product-7
1 ↓ -91%
100
53%
10Product #10
product-10
1 ↓ -99%
100
79%
27Product #27
product-27
1 ↓ -91%
100
56%
11Product #11
product-11
2 ↓ -83%
100
2%
22Product #22
product-22
2 ↓ -99%
100
98%
26Product #26
product-26
15 ↑ 200%
100
76%
9Product #9
product-9
20 ↓ -99%
100
30%
24Product #24
product-24
30 ↓ -99%
100
87%
20Product #20
product-20
34 ↑ 6%
100
53%

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