Mr Goobri Mr Goobri - 2 months ago 14x
jQuery Question

Yii2 - swap ListView for GridView on

I have a ListView, which I create myself. And I have a GridView, using


Both work fine on their corresponding pages. They use the same parameters, such as

<div id="grid">
<?= GridView::widget([....]); ?>


<div id="list">
<?= ListView::widget([....]); ?>

The problem is, when I put them on the same page, the second one loses its interactivity - things like pagination, for example. I have a button to swap out the GridView for the ListView but it doesn't work.

$("#presentation-switcher").click(function() {

I've experimented with different ids, different dataprovides etc. but to no avail. Perhaps I am taking the wrong approach? Any ideas?


Set a new page of item view like _list_item:

    'dataProvider' => $listDataProvider,
    'options' => [
        'tag' => 'div',
        'class' => 'list-wrapper',
        'id' => 'list-wrapper',
    'layout' => "{pager}\n{items}\n{summary}",
    'itemView' => '_list_item',

More Detail