Yii2 Custom Action Button

Use the following format code to make custom action button in Gridview:

[
				'class' => 'yii\grid\ActionColumn',
				'header' => 'Actions',
				'headerOptions' => ['style' => 'color:#337ab7'],
				'template' => "{update} {print} {delete}",
				'buttons' => [
				'view' => function ($url, $model) {
					return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
								'title' => Yii::t('app', 'lead-view'),
					]);
				},

				'update' => function ($url, $model) {
					return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
								'title' => Yii::t('app', 'lead-update'),
					]);
				},
				'delete' => function ($url, $model) {
					return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
						'title' => Yii::t('app', 'lead-delete'),
						'data' => [
							'confirm' => 'Anda yakin ingin menghapus data?',
						],
					]);
                },
                'print' => function ($url, $model) {
					return Html::a('<span class="glyphicon glyphicon-print"></span>', $url, [
						'title' => Yii::t('app', 'lead-print'),
						
					]);
				},

				],
				'urlCreator' => function ($action, $model, $key, $index) {
				if ($action === 'update') {
					$url ='index.php?r=contohuji/update&amp;id_daftar='.Yii::$app->request->get("id")."&amp;id=".$model->id_contohuji;
					return $url;
                }
                if ($action === 'delete') {
					$url ='index.php?r=contohuji/delete&amp;id_daftar='.Yii::$app->request->get("id")."&amp;id=".$model->id_contohuji;
					return $url;
                }
                if ($action === 'print') {
					$url ='index.php?r=contohuji/print&amp;id_daftar='.Yii::$app->request->get("id")."&amp;id=".$model->id_contohuji;
					return $url;
				}
				
				 

				}
				
			],

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.