Пытаюсь реализовать удаление из таблицы через PJAX, но удаляется с перезагрузкой страницы, либо удаляется один элемент а на втором нет реакции на событие:
Код: Выделить всё
<?php Pjax::begin(['id' => 'pjax-container-event-type'])?>
<?= GridView::widget([
'dataProvider' => $dataProviderEventType,
'id' => 'container-event-type',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{deletedict}',
'buttons' => [
'deletedict' => function ($url) {
$id = preg_replace("/[^0-9]/", '', $url);
return "<button class='btn btn-danger' type='button' data-iddel='$id' data-pjax=0 >
<i class='glyphicon glyphicon-remove'></i>
</button>";
},
],
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
Код: Выделить всё
$("#container-event-type button").on("click", function(){
$.ajax({
url: 'delete-dict-event-type',
type: 'POST',
data: {id: $(this).data('iddel')},
success: function(){
$.pjax.reload('#pjax-container-event-type');
return true;},
error: function(){ alert('Что то пошло не так...');}
});
return false;
});