ajax - yii2 -> Modal Dialog on Gridview's update button does not work after searching or change pagination on gridview -



ajax - yii2 -> Modal Dialog on Gridview's update button does not work after searching or change pagination on gridview -

reference yii2 modal dialog on gridview view , update button shows same content both buttons , how implement yii2 modal dialog on gridview view , update button?

i got modal dialog clicking update button on gridview right id parameter selected row. when used searching , pagination on gridview problem occurred. modal dialog seem not working anymore modal dialog shown clicking update button id parameter not match selected row. honest, seem gridview not know registerjs anymore. can kindly advise how solve problem?

<?php $gridcolumns = [ [ //'class' => 'kartik\grid\editablecolumn', 'attribute' => 'branch_id', 'pagesummary' => true, ], [ 'class' => 'kartik\grid\actioncolumn', 'template' => '{update} {delete}', 'headeroptions' => ['width' => '20%', 'class' => 'activity-view-link',], 'contentoptions' => ['class' => 'padding-left-5px'], 'buttons' => [ 'update' => function ($url, $model, $key) { homecoming html::a('<span class="glyphicon glyphicon-star-empty"></span>','/branches/update?id='.$key.'', [ 'class' => 'activity-view-link', 'title' => yii::t('yii', 'update'), 'data-toggle' => 'modal', 'data-target' => '#activity-modal', 'data-id' => $key, 'data-pjax' => '0', ]); }, ], ], ];?> <?php pjax::begin(); ?> <?php echo gridview::widget([ 'dataprovider' => $dataprovider, 'filtermodel' => $searchmodel, 'columns' => $gridcolumns, // 'containeroptions' => ['style'=>'overflow: auto'], // set when $responsive = false 'headerrowoptions'=>['class'=>'kartik-sheet-style'], 'filterrowoptions'=>['class'=>'kartik-sheet-style'], 'pjax' => true, // pjax set true demo 'pjaxsettings'=>[ 'nevertimeout'=>true, 'beforegrid'=>'branches data', 'aftergrid'=>'my fancy content after.', 'enablepushstate' => false, 'options' => ['id' => 'branchesgrid'], ], 'bordered' => true, 'striped' => true, 'condensed' => true, 'responsive' => true, 'hover' => true, 'floatheader' => true, 'panel' => [ 'type' => gridview::type_primary ], ]); ?> <?php yii\widgets\pjax::end() ?> <?php $this->registerjs( ' $(".activity-view-link").click(function(e) { var fid = $(this).closest("tr").data("key"); $.get( "update", { id: fid }, function (data) { $("#activity-modal").find(".modal-body").html(data); $(".modal-body").html(data); $("#activity-modal").modal("show"); } ); }); '

); ?>

<?php modal::begin([ 'id' => 'activity-modal', 'header' => '<h4 class="modal-title">branches updatez</h4>', 'size'=>'modal-lg', 'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">close</a>',

]); ?>

this happenes because bind click event handler in js elements rendered. handler affects on elements on first page. , after ajax update elements disapear. need reactivate click handler after each pjax update.

<?php pjax::begin(['id'=>'some_pjax_id']); ?> <?php echo gridview::widget([ 'dataprovider' => $dataprovider, 'filtermodel' => $searchmodel, 'columns' => $gridcolumns, // 'containeroptions' => ['style'=>'overflow: auto'], // set when $responsive = false 'headerrowoptions'=>['class'=>'kartik-sheet-style'], 'filterrowoptions'=>['class'=>'kartik-sheet-style'], 'pjax' => true, // pjax set true demo 'pjaxsettings'=>[ 'nevertimeout'=>true, 'beforegrid'=>'branches data', 'aftergrid'=>'my fancy content after.', 'enablepushstate' => false, 'options' => ['id' => 'branchesgrid'], ], 'bordered' => true, 'striped' => true, 'condensed' => true, 'responsive' => true, 'hover' => true, 'floatheader' => true, 'panel' => [ 'type' => gridview::type_primary ], ]); ?> <?php yii\widgets\pjax::end() ?> <?php $this->registerjs( ' function init_click_handlers(){ $(".activity-view-link").click(function(e) { var fid = $(this).closest("tr").data("key"); $.get( "update", { id: fid }, function (data) { $("#activity-modal").find(".modal-body").html(data); $(".modal-body").html(data); $("#activity-modal").modal("show"); } ); }); } init_click_handlers(); //first run $("#some_pjax_id").on("pjax:success", function() { init_click_handlers(); //reactivate links in grid after pjax update }); ');

ajax gridview modal-dialog yii2

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -