Yii Framework Forum: How to use CGridView with condition - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to use CGridView with condition Rate Topic: -----

#1 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 18 January 2010 - 06:55 AM

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',
		),
	),
)); ?>

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 18 January 2010 - 08:25 AM

You should do this with the data provider, not grid view:
$dataProvider=new CActiveDataProvider('ModelClass', array(
    'criteria'=>array(
         'condition'=>'....'
    ),
));

1

#3 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 18 January 2010 - 09:42 AM

多谢了,qiang!
0

#4 User is offline   jiania 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 25-October 09

Posted 19 January 2010 - 09:31 AM

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

#5 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 19 January 2010 - 12:10 PM

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

#6 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 301
  • Joined: 18-April 09
  • Location:Leipzig, Germany

Posted 29 January 2010 - 04:38 PM

View Postqiang, on 19 January 2010 - 12:10 PM, said:

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 !
0

#7 User is offline   Alexandr Dorogikh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 29-September 09
  • Location:Ukraine, Bila Tserkva

Posted 30 January 2010 - 07:50 AM

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
0

#8 User is offline   Rashed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 13-December 15

Posted 13 December 2015 - 02:03 AM

View Postqiang, on 18 January 2010 - 08:25 AM, said:

You should do this with the data provider, not grid view:
$dataProvider=new CActiveDataProvider('ModelClass', array(
    'criteria'=>array(
         'condition'=>'....'
    ),
));


0

#9 User is offline   Rashed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 13-December 15

Posted 13 December 2015 - 02:03 AM

Thanks. Its works.
0

#10 User is offline   reykel 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 21-June 15
  • Location:Camaguey, Cuba

Posted 13 December 2015 - 06:47 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users