Created
January 4, 2016 01:52
-
-
Save c006/33f7c24ffeb17a102ceb to your computer and use it in GitHub Desktop.
Yii2 GirdView example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?= GridView::widget([ | |
'dataProvider' => $dataProvider, | |
'filterModel' => $searchModel, | |
'showHeader' => TRUE, | |
'emptyCell' => '-', | |
'columns' => [ | |
['class' => 'yii\grid\SerialColumn'], | |
[ | |
'label' => 'Image', | |
'format' => 'raw', | |
'value' => function ($data) { | |
$url = "/images/products/" . $data['image']; | |
return Html::img($url, ['alt' => $data['name'], 'height' => 50]); | |
}, | |
], | |
'model', | |
'name', | |
'qty', | |
'price', | |
[ | |
'label' => 'Discount', | |
'format' => 'raw', | |
'value' => function ($data) { | |
return ($data['discount']) ? $data['discount'] . '% Off' : ''; | |
}, | |
], | |
[ | |
'label' => 'Auto Ship', | |
'format' => 'raw', | |
'value' => function ($data) { | |
$auto_ship = ModelHelper::getAutoShipLinkName($data['auto_ship']); | |
return (sizeof($auto_ship)) ? $auto_ship['duration'] . ' ' . $auto_ship['type'] : ''; | |
}, | |
], | |
[ | |
'label' => 'Totals', | |
'format' => 'raw', | |
'value' => function ($data) { | |
return '$' . number_format($data['price'] * $data['qty'], 2); | |
}, | |
], | |
['class' => 'yii\grid\ActionColumn', | |
'template' => '', | |
], | |
], | |
]); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment