Yii2 Modal form update on gridview no showing up after reload gridview with pjax


Keywords:gridview 


Question: 

Sorry for my bad English.

I created modal form to create and update data and reload container grid with pjax. Everything works fine, but modal form for update does not appear if the container grid is loaded up. which appears only regular update form.

But if the page I refresh manually, modal form for update shows up. This is code for update button in my gridview:

[
  'class' => 'yii\grid\ActionColumn',
      'template' => '{view} {update} {delete}',
      'buttons' => [
         'update' => function($url, $model) {
             return Html::a('<span class="glyphicon glyphicon-pencil"></span>', 
                 ['update', 'id' => $model->id], [
                    'class' => 'showModalButton',
                    'data-pjax' => 0,
                    'aria-label' => 'Update',
                    'title' => 'Update'
                  ]);
        }]
]

any suggestion?


1 Answer: 

May Be You are using this code to open model :

$('.showModalButton').click(function(){
  $('#model_name').modal('show');
});

Replace with below code :

$('body').on('click', '.showModalButton', function() {

  $('#model_name').modal('show');

});