Filter And Pagination With Carraydataprovider

Hi All,

I have been trying to use CArrayDataprovider with filter and pagination. This works all fine when i first load the page.

The problem starts when I use my search. The first time it loads the data correctly. But once I paginate from the page, it loads all the data. Not the ones that were searched for. Below is my code:

Controller:




public function actionTest() {

        /* pagination with CArrayDataProvider */

        $sql = $this->searchLogs();


        $callLogs = Yii::app()->db->createCommand($sql)->queryAll();


        $dp = new CArrayDataProvider($callLogs, array(

            'keyField' => 'ticket_id',

            'pagination' => array(

                'pageSize' => 10,

            ),

        ));


        $this->render('test', array(

            'model' => $dp,

        ));

    }



View:




<?php

        $gridWidget = $this->widget('bootstrap.widgets.TbGridView', array(

            'dataProvider' => $model,

            'columns' => array(

                

                'id: Id',

                'name: Name',

                'mobile: Mobile',

                'created_date: Created Date',

                array(

                    'class' => 'bootstrap.widgets.TbButtonColumn',

                    'header' => 'Operations',

                    'template' => '{view}',

                    

                ),

            ),

        ));

        ?>



Thank you.

  • Debug and set a breakpoint (or var_dump) inside the method ‘fetchData’ of the CArrayDataprovider.

    This method should slice the array by pagination offset/limit.

    Check why offset/limit is not correct.

  • Because of ressource issues I would not use a CArrayDataprovider because always all data will be fetched (depending on searchLogs sql, count of log entries?). Try a CSqlDataprovider instead.

Can you please try that pass the process output when page was render

for ex:


$this->render('index',array('model'=>$model),false,true)

I tried using the dump and the offset is set properly. But I have no idea why it doesnot work when i click on the page 2 or 3 in the pagination.

I also tried using the false, true attributes while rendering the Grid view but doesnot seem to help.

QFE. Also: Grid filters are a feature of [font=“Courier New”]CActiveDataProvider[/font]s. You won’t get them easily with other data providers.

How do you construct the SQL in your "searchLogs" method? And how do you pass the search parameters from the view to the controller?

Note that CGridView uses "get" method to pass the pagination and sorting parameters, and you would be better use "get" instead of "post" for your search functionality.