Answer the question
In order to leave comments, you need to log in
How to configure Ajax and GridView to work?
That's the day I rack my brains, how can I do so that a person can change the data in the table (GridView) and the table is automatically updated without reloading the page? Tried with Pjax - didn't work. Is it possible via Ajax?
An example of Pjax code that came out of my
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.3em !important'],
'format' => 'raw',
'filter' => [
0 => 'Нету',
1 => 'Есть',
],
'value' => function ($model, $key, $index, $column) {
$active = $model->{$column->attribute} === 1;
return Html::a(
$active ? 'Есть' : 'Нету',
['task/doc', 'id' => $model->id],
[
'class' => 'pjax label label-' . ($active ? 'success' : 'warning'),
]
);
},
],
?>
<?php Pjax::end(); ?>
public function actionDoc($id)
{
$model = Task::findOne($id);
$model->doc = !$model->doc;
$model->save(false);
$this->redirect('index');
}
Answer the question
In order to leave comments, you need to log in
Tried with Pjax - didn't work. Is it possible via Ajax?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question