CGridView filtering

Hi guys,

How to fitler the result in CgridView when i using $dataProvider instead of $model->search(). Anyone got try it before?


    $dataProvider = new CSqlDataProvider($sql, array(

                'totalItemCount' => $count,

                'pagination' => array(

                    'pageSize' => 10,



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

        'id' => 'detail-grid',

        'dataProvider' => $dataProvider,

        //'filter' => $model,              ----> filter based on $dataProvider 

        'columns' => array(


                'name' => 'created',

                'header' => 'Time'



                'name' => 'machine_tag',

                'header' => 'Machine Name'



                'name' => 'description',

                'header' => 'Product'



Yeah, but you would need to add a criteria based on the content of $model to the data provider. So what would be the benefit? Using $model->search() or a similar method is consistent with MVC principles.

Edit: I think the post below has the answer to the very question you asked.


Use Criteria to set search conditions


$criteria=new CDbCriteria;

$criteria->condition = time() . ’ > end_time’;

$dataProvider=new CActiveDataProvider(‘Campaign’, array(‘criteria’=>$criteria));