Hello Friends.
I have face one problem while deleting the row of
Gridview
with request of ajax using
Pjax
. but when i filtered or sort the Grid, than i delete row so after the deleting row page redirect to index action. and all the filter and sorting reseted.
I try to remove
redirect
method in controller but still not work.
How can prevent redirecting to
index
or send ajax request same as Yii 1.0 gridview ?
my code is.
view file
<?php \yii\widgets\Pjax::begin([
'id' => 'pjax-list',
'enablePushState' => false,
'enableReplaceState' => false,
]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'stu_category_name',
//['class' => 'yii\grid\ActionColumn'],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete}',
'buttons' => [
'view' => function ($url, $model) {
return ((Yii::$app->user->can("/student/stu/view")) ? Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, ['title' => Yii::t('app', 'View'),]) : '');
},
'delete' => function ($url, $model) {
return ((Yii::$app->user->can("/student/stu/delete")) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => Yii::t('app', 'Delete'), 'data' => ['confirm' => 'Are you sure you want to delete this item?','method' => 'post'], 'data-ajax' => '1']) : '');
}
],
],
],
]); ?>
<?php \yii\widgets\Pjax::end(); ?>
controller file
public function actionDelete($id)
{
$model = StuCategory::findOne($id);
$model->delete();
//return $this->redirect(['index']);
}