Mr Goobri Mr Goobri - 1 year ago 248
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download