How to configure Ajax and GridView?

That's the day scratching their head like I do to people could change data in the table (GridView) and the table will be automatically refreshed without reloading the page? I tried using Pjax - did not work. Is it possible through Ajax?

Sample code in Pjax which was released I

view/index.php
$this->registerJs(
 '$( ".pjax" ).click(function(event) {
 $.pjax.reload({container: "#tasks"});
});

 <?php Pjax::begin(['id' =--> 'tasks']); ?>
 <?= GridView::widget([
 'dataProvider' =--> $dataProvider,
 'filterModel' => $searchModel,
 'columns' => [
[
 'class' => 'yii\grid\CheckboxColumn',
],
[
 'attribute' => 'doc',
 'contentOptions' => ['style' => 'font-size: 1.3 em !important'],
 'format' => 'raw',
 'filter' => [
 0 => 'No',
 1 => 'Is',
],
 'value' => function ($model, $key, $index, $column) {
 $active = $model->{$column->attribute} === 1;
 return Html::a(
 $active ? 'There' : 'No',
 ['task/doc', 'id' => $model->id],
[
 'class' => 'pjax label label-' . ($active ? 'success' : 'warning'),
]
);
},
],
?>

 <?php Pjax::end(); ?>


conreollers/TaskController.php
public function actionDoc($id)
{
 $model = Task::findOne($id);
 $model->doc = !$model->doc;
$model->save(false);

$this->redirect('index');
 }


The table is updated when you click, but the data is not changing + if you do it in the middle of the table - it throws up.
July 4th 19 at 23:20
1 answer
July 4th 19 at 23:22
I tried using Pjax - did not work. Is it possible through Ajax?


Pjax is a jquery plugin which uses pushState and ajax, and provides the ability to load the page completely when clicking on links, and partly, but with the appropriate page title and a possible return back


It turns out that You are already using ajax.

In the controller action why would You put the redirect? Where do You get id? Are you sure he is? Check.
How do You send data to the server? You want to hang-click on a table cell?
He takes the id correctly, I looked it up (the column consists of applications, it's application id). Redirect I put, since when pressing the button - clicks a link (task/Doc&id=1234), and returns to techsup page (found a crutch on the forum). Yes, I want when user clicks on the column it was possible to change the data (enter text) or just change the option and the table is updated automatically (this feature is definitely needed). He has climbed a lot of forums and what did not have - modesta_Medhurst21 commented on July 4th 19 at 23:25
:
When you click to show a modal window with a form in which you write text and send to the server.
https://nix-tips.ru/yii2-primeryaem-pjax-na-active... - Dion77 commented on July 4th 19 at 23:28
: Thanks for the info, I will try - modesta_Medhurst21 commented on July 4th 19 at 23:31

Find more questions by tags Yii