Closed maximpn closed 8 years ago
So you expect Pjax to follow the redirect of the delete action (assuming it redirects to the index page that contains the gridview) and reload the grid only instead of following the redirect for the whole page?
I think this is simplest and straight way. But the PJAX headlines will be lost after the browser will be redirected from delete action to the index action. The index action thinking that redirect request is usually not PJAX (or AJAX) request and return full web page. Sure, PJAX will reload full web page.
And other question: what about filter and page params? Because they will be lost after redirect.
P.S. I think true way use AJAX request to delete action and then refresh current page by pjax update.
What is the philosophy of Yii2 about buttons with AJAX action in GridView?
I am using this enhancement of yii.handleAction method in yii.js:
if (isAjax) {
$.ajax({
url: $form.attr('action'),
method: $form.attr('method'),
data: $form.serialize(),
success: function (data) {
if (data) {
var $pjaxContainer = $e.closest('.pjax');
if ($pjaxContainer.length && $.pjax.reload) {
$.pjax.reload('#' + $pjaxContainer.attr('id'), {
url: window.location.href
});
} else {
window.location.reload();
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error was thrown while AJAX request: ' + textStatus);
}
});
} else {
$form.trigger('submit');
}
It's requires that pjax container has .pjax class and button or link has data-ajax="1" attribute.
this? use yii\widgets\Pjax; Pjax::begin(); echo GridView::widget([....] Pjax::end();?>
I have seen some many posts about this problem, but all of they don't introduce clarity. I am use solution from box. GridView + Pjax and delete action. When I will try to delete item the Pjax reload all page, when I do redirect in my delete acton. What I do wrong?
Yii 1.1 send ajax request and then update GridView by update js method. I don't see similar behavior in Yii 2.