我使用Pjax與Gridview,我希望我所有的操作按鈕做Ajax。默認情況下,他們沒有,所以我GOOGLE了,並找到了刪除數據的方式 - pjax = 0.但仍然沒有ajax請求,所有這些都是常規請求。Yii 2:Pjax + Gridview刪除不發送Ajax請求
很多人都有這個問題,我也找不到解決方案。
我已經按照:
我的代碼:
<?php Pjax::begin(['id' => 'employee-timesheet-grid-id', 'timeout' => false, 'enablePushState' => false, 'clientOptions' => ['method' => 'POST']]) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'Employee',
'value' => function ($model) {
return $model->employeePayRate->employeeName;
},
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete}',
'buttons' => [
'delete' => function ($url , $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url,
['data-confirm' => 'Are you sure you want to delete this item?', 'data-method' =>'POST']);
}
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
$url = Url::to(['employee-time-sheet/view', 'id' => $model->id]);
return $url;
} else if ($action === 'delete') {
$url = Url::to(['employee-time-sheet/delete', 'id' => $model->id]);
return $url;
}
}
],
],
]); ?>
<?php Pjax::end(); ?>
有沒有人發現這個問題解決了嗎?
我已經做了解決方案 –