Tutorial Yii2 Bagian 30 : Memanfaatkan Kartik Gridview Widget
Sekarang kita akan memanfaatkan widget dari kartik yaitu gridview widget untuk menampilkan purchase order. 1. Install kartik gridview widget dari website http://demos.krajee.com/grid di folder advanced :
1 |
sudo composer require kartik-v/yii2-grid "@dev" |
2. Modifikasi index.php milik purchaseorder yang berada di folder backends\views\purchaseorder :
1 |
use kartik\grid\GridView; |
Sehingga file index.php menjadi seperti ini :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php use yii\helpers\Html; use kartik\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\PurchaseOrderSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Purchase Orders'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="purchase-order-index"> <h1><?= Html::encode($this->title) ?></h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?= Html::a(Yii::t('app', 'Create Purchase Order'), ['create'], ['class' => 'btn btn-success']) ?> </p> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ [ 'class'=>'kartik\grid\ExpandRowColumn', 'value'=> function ($model, $key, $index, $column){ return GridView::ROW_COLLAPSED; }, 'detail' => function ($model,$key,$index,$column){ $searchModel = new PurchaseOrderItemSearch(); $searchModel->po_id = $model->id; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return Yii::$app->controller->renderPartial('_poitems',[ 'searchModel' => $searchModel, 'dataProvider'=> $dataProvider, ]); }, ], 'po_no', 'description:ntext', ['class' => 'yii\grid\ActionColumn'], ], ]); ?> </div> |
3. Buat file php partial di folder view Read more about Tutorial Yii2 Bagian 30 : Memanfaatkan Kartik Gridview Widget[…]