Yii2: How to Create Editable Row in Gridview

Setup 1 – View

Put the following code inside gridview:

                'attribute' => 'nilai_tugas',
                'value' => function ($model)
                    return $model->nilai_tugas;
                'editableOptions'=> function ($model, $key, $index) {
                    return [
                        'formOptions'=>['action' => ['krs-detail/editNilai']],

Setup 2 – Controller

Put the following code into controller file:

use kartik\grid\EditableColumnAction;
use yii\helpers\ArrayHelper;
use backend\models\KrsDetail;

and then create function:

public function actions()
        return ArrayHelper::merge(parent::actions(), [
            'editNilai' => [                                       // identifier for your editable action
                'class' => EditableColumnAction::className(),      // action class name
                'modelClass' => KrsDetail::className(),            // the update model class

Below is the result of editable Gridview:

2 thoughts on “Yii2: How to Create Editable Row in Gridview

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.