Yii2 Editable column

Can anyone suggest any tutorial on editable column in gridview.I am using Yii2 and stuck with it. There are some questions:

1.How can I get dropdown list data in editable column from model?

2.How can I post the value in controller?

3.How can I save the values in model using controller function?

Thanks in advance. :rolleyes:

I have worked with the first and second issue.

I have modified my view file:


$gridColumns= [

  'patient_no',

  'category_name',

  'sdv_text',

  [

    'class' => 'kartik\grid\EditableColumn',

    'attribute'=>'sdv_status',

    'pageSummary' => true,

    'editableOptions'=> [

      'header' => 'profile',

      'format' => Editable::FORMAT_BUTTON,

      'inputType' => Editable::INPUT_DROPDOWN_LIST,

      'data'=> $StatusList,

    ]

  ],

  //  'date_sdv_performed',

  [

    'class' => 'kartik\grid\EditableColumn',

    'attribute'=>'date_sdv_performed',

    'editableOptions' => [

      'header' => 'Date Sdv Performed',

      'inputType'=>\kartik\editable\Editable::INPUT_WIDGET,

      'format'=>\kartik\datecontrol\DateControl::FORMAT_DATE,

      'widgetClass'=> 'kartik\datecontrol\DateControl',

    ],

  ],

  [

    'class' => 'kartik\grid\EditableColumn',

    'attribute'=>'comments',

    'hAlign' => 'top',

    'vAlign' => 'middle',

    'width'=>'100px',

    'headerOptions' => ['class' => 'kv-sticky-column'],

    'contentOptions' => ['class' => 'kv-sticky-column'],

    'pageSummary' => true,

  ],

];

GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'layout'=>"{items}\n{pager}",

        'pjax'=>true,

        'toolbar' => [

          '{export}',

          '{toggleData}'

        ],

        'responsive'=>true,

        'hover'=>true,

        'columns' => $gridColumns

      ]);

And in my controller:


public function actionMonitoring($site_name)

  {

    $this->layout = 'sdv-carolina-main';

    $Countries      = new Countries;

    $model          = new Flagging;

    $searchModel    = new FlaggingSearch();

    $dataProvider   = $searchModel->monitoringsearch($site_name);

    $allocatedsites = new AllocatedSites;

    if (Yii::$app->request->post('hasEditable')) 

    {

      $model  = $this->findModel($model['flagging_id']);

      $out    = Json::encode(['output'=>'', 'message'=>'']);

      $post = [];

      $posted = current($_POST['Flagging']);

      $post['Flagging'] = $posted;

      if ($model->load($post)) {

        $model->save();

        $output = '';

        if (isset($posted['sdv_status'])) 

        {

          $output =  $model->sdv_status;

        }

         $out = Json::encode(['output'=>$output, 'message'=>'']); 

      }

      echo $out;

      return;

    }

    return $this->render('monitoring',

      [

        'searchModel' => $searchModel,

        'dataProvider' => $dataProvider,

        'Countries' => $Countries,

        'model'=>$model,

        'allocatedsites' => $allocatedsites,

      ]);

  }

I know I can update the model if I get the table id.But how can I get the table id from the gridview?

As I didn’t use that in my gridview.

Please help me.Thanks.

Hello! Can I use the editable column in listviews itemview?