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(

            array(

                'name' => 'created',

                'header' => 'Time'

            ),

            array(

                'name' => 'machine_tag',

                'header' => 'Machine Name'

            ),

            array(

                'name' => 'description',

                'header' => 'Product'

            ),

Thx.

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.

/Tommy

Use Criteria to set search conditions

=======================================

$criteria=new CDbCriteria;

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

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

$this->render(‘index’,array(

'dataProvider'=>$dataProvider,


))