How to use CGridView with condition

the CGridview all the data,I don’t want to show all the data ,i want show some data with condition,like survey_id = 1,how can i do that?




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

	'dataProvider'=>$dataProvider,

	'columns'=>array(

		'id',

		'survey_id',

		'name',

		'name_en',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



You should do this with the data provider, not grid view:




$dataProvider=new CActiveDataProvider('ModelClass', array(

    'criteria'=>array(

         'condition'=>'....'

    ),

));



多谢了,qiang!

by the way ,how to show some data with condition in relation model when use CGridview?

That can be similarly done except that you also need to specify the ‘with’ option in the query criteria.

Does this also work with MANY_MANY relations?





$criteria = new CDbCriteria;

$criteria->with = array('categories') // categories is a MANY_MANY related model

$criteria->condition = array('categories = 54') // <-- want to display every ROW that has the category 54 



is this possible to add some MANY_MANY intelligent logic to the CDbCriteria like this ? thank you !

Yesterday I asked about this on russian forum… but I didn’t heard any answers.

I solve this in… IMHO very ugly way.

I use some additional model attributes and handful of subqueries.

Currently I try to find more elegant solution

Thanks. Its works.

I think you should get a more extensive explanation. If still open to it please tell me