I'm newbie in yii2. Grouping options are working properly in field column. But i need grouping in actionColumn in yii2 gridview.
I want to show a single button for multiple row which has common attribute value. My table data:
details_table:
id parent_id name
1 1 One
2 1 Two
3 2 Three
4 2 Four
I created url using parent id as like domain?parent_id=1. So I want to display Single button for row 1 and 2. And for 3 and 4.
<?php
$gridColumns = [
[
'attribute' => 'date',
'label' => 'Requisition Date',
'value' =>function ($model, $key, $index, $widget) {
return date("d-M-Y",strtotime($model->date));
},
'vAlign'=>'middle',
'hAlign'=>'center',
'width' => '10%',
],
[
'attribute' => 'invoice_no',
'label' => 'Invoice No',
'width' => '10%',
'vAlign'=>'middle',
'hAlign'=>'center',
'group' => true,
],
[
'attribute' => 'depo_id',
'label' => 'Depo Name',
'width' => '10%',
'value' =>function ($model, $key, $index, $widget) {
return Depo::getDepoName($model->depo_id);
},
'filterType'=> GridView::FILTER_SELECT2,
'filter' => ArrayHelper::map(Depo::find()->orderBy('depo_name')->asArray()->all(),'id','depo_name'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Select Depo'],
'vAlign'=>'middle',
'hAlign'=>'center',
],
[
'attribute' => 'expected_received_date',
'label' => 'Expected Received Date',
'value' =>function ($model, $key, $index, $widget) {
return date("d-M-Y",strtotime($model->expected_received_date));
},
'vAlign'=>'middle',
'hAlign'=>'center',
'width' => '10%',
],
[
'attribute' => 'model_id',
'label' => 'Product Name',
'width' => '10%',
'value' =>function ($model, $key, $index, $widget) {
return Prodmodels::getProductName($model->model_id);
},
'filterType'=> GridView::FILTER_SELECT2,
'filter' => ArrayHelper::map(Prodmodels::find()->orderBy('model_name')->asArray()->all(),'id','model_name'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Select Product'],
'vAlign'=>'middle',
'hAlign'=>'center',
],
[
'attribute' => 'qty',
'label' => 'qty(Crtn/Bag)',
'vAlign'=>'middle',
'hAlign'=>'center',
'width' => '10%',
],
[
'attribute' => 'status',
'label' => 'Status',
'width'=>'10%',
'value' =>function ($model, $key, $index, $widget) {
if($model->status==1){
return "Approved";
}else if($model->status==2){
return "Canceled";
}else{
return "New";
}
},
'filterType'=> GridView::FILTER_SELECT2,
/*ArrayHelper::map(Proditems::find()->orderBy('item_name')->asArray()->all(), 'id', 'item_name')*/
'filter'=>array(0=>'New',1=>'Approved',2=>'Canceled'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Select Status'],
'vAlign'=>'middle',
'hAlign'=>'center',
],
[
'class' => '\kartik\grid\ActionColumn',
'template' => '{view}{update}{delete}',
'width' => '10%',
'vAlign'=>'middle',
'hAlign'=>'center',
'buttons' => [
'view' => function ($url, $model) {
return Html::button('<i class="fa fa-eye"></i>', ['id' => 'btnShow' . $model->id, 'value' => $url, 'class' => 'btnView btn btn-sm margin-right-5px btn-success', 'title' => 'View']);
},
'update' => function ($url, $model) {
//return Html::button('<i class="fa fa-eye"></i>', ['id' => 'btnShow' . $model->id, 'value' => $url, 'class' => 'btnView btn btn-sm btn-success margin-right-5px', 'title' => 'View']);
return Html::a('<i class="glyphicon glyphicon-pencil"></i>', $url, ['class' => 'btn btn-sm margin-right-5px btn-success', 'title' => 'Update Depo Requisition']);
},
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, [
'title' => Yii::t('app', 'Delete'),
'class' => 'btn btn-sm margin-right-5px btn-danger',
'data-confirm' => Yii::t('yii', 'Are you sure you want to Delete?'),
'data-method' => 'post',
]);
},
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
return $url = \Yii::$app->getUrlManager()->createUrl(['module/supplychain/csr/view', 'csr_no' => $model->csr_no]);
}
if ($action === 'update') {
return $url = \Yii::$app->getUrlManager()->createUrl(['module/supplychain/csr/update', 'csr_no' => $model->csr_no]);
}
if ($action === 'delete') {
return $url = \Yii::$app->getUrlManager()->createUrl(['module/supplychain/csr/delete', 'csr_no' => $model->csr_no]);
}
}
]
];
?>
<?=GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'toolbar' => [
['content' =>
Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create'], ['class' => 'btn btn-success', 'title' => 'Create Depo Requisition', 'id' => 'modelButton']) . ' ' .
Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => 'reset grid'])
],
'{export}',
'{toggleData}',
],
'panel' => [
'heading' => '<div class="data-heading">Depo Requisition Info</div>',
'type' => 'success',
'before' => \Yii::$app->session->getFlash('flashMessage'),
'headingOptions' => [
'class' => 'panel-heading'
]
],
'bordered' => true,
'hover' => true,
'responsive' => true,
'condensed' => true,
]); ?>