Yii Framework Forum: Gridview Filtering For Relational Model - Yii Framework Forum

Jump to content

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

Gridview Filtering For Relational Model How to do filtering for relational model with other relation Rate Topic: -----

#1 User is offline   MoHaMmAd_K 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-December 12

Posted 08 December 2012 - 03:03 AM

hallo everyone,

I have 3 models each one have relation with others, I want to configure the filter for that in GridView

this is the models:

serviceCenter Model:

public function relations()
	{
		return array(
			'ownerData' => array(self::BELONGS_TO, 'Ownerdata', 'ownerData_id'),
        }



OwnerData Model :

public function relations()
	{
		return array(
			'provinceData' => array(self::BELONGS_TO, 'Provincedata', 'ProvinceData_id'),
		);
	}


and Provincedata Model has these columns
integer $id
string $provinceName

now what i have to do, is display the province name from ServiceCenter admin page with filter on it.

the grid view in admin page:
$this->widget('zii.widgets.grid.CGridView', array(
		'id'=>'my-grid',
		'dataProvider'=>$servic->searchEX(),
		'filter'=>$servic,
		'columns'=>array(
		'id',
		 array( 
		 	'name' => 'ownerData.name',
			'filter' => CHtml::activeTextField($servic->searchName, 'name'),
		 ),
		array(
			'name'=>'ownerData.ProvinceData_id',
		),
               
                ....


Note: in the ownerData.name the filter work correctly
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,082
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 08 December 2012 - 05:28 AM

check this out

http://www.yiiframew...l-in-cgridview/
0

#3 User is offline   MoHaMmAd_K 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-December 12

Posted 09 December 2012 - 07:10 AM

View Postalirz23, on 08 December 2012 - 05:28 AM, said:



thank you,

but this work with tow models and relation between its,

in my case I have
--- Model A <--> Model B relation
--- Model B <--> Model C relation

And in admin page (Model A) I need filtering the data which is at the (Model C)
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 09 December 2012 - 08:57 AM

Hi MoHaMmAd_K, welcome to the forum.

It's almost the same ... just add the relation of "ownerData.proviceData" to "with". :)
$criteria = new CDbCriteria;
$criteria->with = array( 'ownerData', 'ownerData.provinceData' );
...
$criteria->compare( 'ownerData.name', $this->searchName, true );
$criteria->compare( 'provinceData.provinceName', $this->searchProviceName, true );
...


http://www.yiiframew...elational-query
0

#5 User is offline   m@ster 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 02-April 12

Posted 14 December 2012 - 05:28 AM

I have the same problem

where you define "searchName" ?
because I will return this error:
PHP notice

Undefined variable: searchName


thanks
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 14 December 2012 - 07:34 AM

@m@ster
Did you read the link that alirz23 has suggested?
0

#7 User is offline   m@ster 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 02-April 12

Posted 17 December 2012 - 09:30 AM

View Postsoftark, on 14 December 2012 - 07:34 AM, said:

@m@ster
Did you read the link that alirz23 has suggested?

read and Problem Solved :rolleyes:
thanks
0

#8 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 386
  • Joined: 08-June 10
  • Location:France (Ile-de-France/Val d'Oise)

Posted 03 February 2013 - 03:56 PM

I just released a behavior to help with this: Related Search Behavior
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