Update div use Pajax
index.php
use yii\widgets\Pjax;
<?
$stav = Stav::find();
$searchModel2 = new StavSearch();
$dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams);
?>
<?= Html::button('Нажми меня!', ['id' => 'myBtn', 'class' => 'teaser']); ?>
<?php Pjax::begin([ 'id' => 'pjaxContent']); ?>
<!-- Здесь контент -->
<?= GridView::widget([
'dataProvider' => $dataProvider2,
'filterModel' => $searchModel2,
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'id',
'contentOptions' => ['style' => 'min-width: 10%;'],
],
[
'attribute' => 'uuid',
'contentOptions' => ['style' => 'min-width: 30%;'],
],
[
'attribute' => 'name',
'contentOptions' => ['style' => 'min-width: 40%;'],
],
[
'class' => 'yii\grid\ActionColumn',
'header' => '<center>Opravit</center>',
'template' => '{update}',
'contentOptions' => ['style' => 'min-width:10%; text-align: center;'],
],
[
'class' => 'yii\grid\ActionColumn',
'header' => '<center>Smazat</center>',
'template' => '{delete}',
'contentOptions' => ['style' => 'min-width:10%; text-align: center;'],
],
],
]); ?>
<?php Pjax::end(); ?>
ajax.js
$('#myBtn').on('click', function (e) {
e.preventDefault();
$.pjax.reload({container: '#pjaxContent'});
return false;
});
Anebo pro div
$.pjax.reload('#boxPajax', {timeout : false});