CGridView pagination with filter

Hello All

i have view with gridview and activefrom to set filter by date

gridview recieves data from dataprovider

dataprovider has pagination enabled

so the question. when switching pages filter is lost.

i’m understanding the system wrong (assuming it should preserve filter, once set in criteria condition)

or i should save filter options in session and popup them everytime on pagination?

P.S. there is no code in post 'cause the issue not in it, but in technique itself.

P.P.S. sorry for my awfull english, there is the end of working day and i even think badly now)

Hi there

I think you’d have to post imho. I personally have persistent filters, even with complex CDbCriteria in my search. I’ve just re-tried to make sure and it works.

PS I’m filtering the standard ajax way and using standard CGridView or GroupGridView extension

i have not understand you. are you setting filters in gridview itself? and selecting all data from db?

Well code is better :rolleyes: I use standard one from Gii, and it works (pagination is on by default, at least with the standard code).


public function actionAdmin() {

    $model = new MyModel('search');


    if (isset($_GET['MyModel']))


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

        'model' => $model,




public function search() {

    $criteria = new CDbCriteria;

    $criteria->compare('someModelAttribute', $this->someModelAttribute);

    $criteria->compare('…', $this->…, true);

    return new CActiveDataProvider($this, array(

        'criteria' => $criteria,




Yii::app()->clientScript->registerScript('search', "

$('.search-form form').submit(function(){

    $.fn.yiiGridView.update('myModel-grid', {

        data: $(this).serialize()


    return false;




<?php $this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'myModel-grid',

    'dataProvider' => $model->search(),

    'filter' => $model,

    'columns' => array(




)); ?>