Pjax Grid

Hi, I’m new to Yii and am looking to see if there is a way to have a table on a page which is populated via ajax/pjax, on load and when filtered?

I see there is docs on pjax, but it only shows wrapping grid view around pjax start and end tags. Doesn’t specificy how it works and where it’s going to get the data to return. Also does it go in the controller or the view?

Many thanks

Really appreciate any help


it sends request to controller action and the result is returned to the view then the pjax widget update it with pushState

How to setup a pjax enabled gridview actioncolumn to display View in a modal? An example would help.

When I set data-target to the modal on index.php and href to controller/view, the modal dialog is displayed before the view, which is rendered on a new page. It does not update the modal.

To clarify - are you trying to display a grid view inside a modal dialog?

Click a ‘view’ actioncolumn icon and the related view should be rendered in a modal.


....grid declaration....

'class' => 'yii\grid\ActionColumn',

'template' => '{view} {update} {delete}',

'buttons' => [

    'view' => function ($url, $model) {

        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [

            'id' => 'view-link',

            'title' => Yii::t('yii', 'View'),

            'data-toggle' => 'modal',

            'data-target' => '#activity-modal',

            'data-pjax' => '1',





...modal declaration (no button since modal will be triggered in actioncolumn)...


<?php Modal::begin([

    'id' => 'activity-modal',

    'header' => '<h2>Hello world</h2>',

    //'toggleButton' => ['label' => 'click me'],

]); ?>

//Should I use view render here? Or use controller/view render

<?= /*$this->render('_view', [

    'model' => backend\models\MyModel::find(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />), //problem here

])*/ ?>

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

You can try renderAjax for injecting JS/CSS scripts and files into the rendering result which are registered with the view.

If I were you I would directly write a javascript/jquery code on the view button to do the following:


[*]read a Json encoded output from the actionView url in controller

[*]on ajax success replace modal body html parsing the above output

[*]trigger modal.show()