Võ Minh Tâm
Võ Minh Tâm

Reputation: 59

When pagination listview display incorrectly

I have action the first i will render a listview with dataprovider a. then when user search i will update dataprovider a to dataprovider b . it is work but I click to view next page data display on page that The data displayed belong dataProvider 'a' not belong 'b'. I don't know why.

This is controller

$data = Post::get();
    if(isset($_POST['btn_search']))
    {
        $a= $_POST['a'];
        $b= $_POST['b'];
        $c= $_POST['c'];
        $data = Post::get($a, $b, $c);
    }
    return $this->render('search', array(
        'data' => $data
    ));

this is view :

 <?php
    \yii\widgets\Pjax::begin([
        'enablePushState' => false,
    ]);
    ?>
    <?=
    ListView::widget([
        'dataProvider' => $data,
        'options' => [
            'tag' => 'div',
            'class' => 'panel-body list-group list-group-contacts',
            'id' => 'list-search',
        ],
        'itemView' => function ($model, $key, $index, $widget) {
            return $this->render('_list_search',['model' => $model]);

            // or just do some echo
            // return $model->title . ' posted by ' . $model->author;
        },
        'itemOptions' => [
            'tag' => false,
        ],
        'pager' => [
            'options' => [
                'style' => 'margin-top: 10px; width: auto; margin-bottom: 10px; margin-right:5px',
                'class' => 'pagination pager'
            ],
            'nextPageLabel' => '<span class="glyphicon glyphicon-chevron-right"></span>',
            'prevPageLabel' => '<span class="glyphicon glyphicon-chevron-left"></span>',
            'maxButtonCount' => 5,
        ],
    ]);
    ?>
    <?php \yii\widgets\Pjax::end() ?>

Please help me. thank all so much.

Upvotes: 0

Views: 599

Answers (1)

Carlos Manzo
Carlos Manzo

Reputation: 99

So what happens is you use one data provider to set pagination but then you pass a different one to the Listview.

Let me see your model, in particular:

public function search($params)
{
...
...
 return $dataProvider;
}

i think the problem is in:

return $this->render('search', array(
    'data' => $data

Upvotes: 0

Related Questions