Yii Framework Forum: Cannot Get Cgridview To Work With Cactivedataprovider - Yii Framework Forum

Jump to content

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

Cannot Get Cgridview To Work With Cactivedataprovider Rate Topic: -----

#1 User is offline   GoofyX 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 180
  • Joined: 15-April 09
  • Location:Thessaloniki, Greece

Posted 12 February 2013 - 04:51 AM

Inside the controller:

$locationsProvider = new CActiveDataProvider('CustomerLocations',
	array(
		'criteria'=>array(
			'select'=>array('t.name AS lname', 'DATEDIFF(t.date_expires, CURDATE()) AS gracePeriod',
				'idCountry.name AS coname', 'idState.name AS sname', 'idCity.name AS cname'),
			'condition'=>'active=1 AND DATEDIFF(t.date_expires, CURDATE()) < :period',
			'params'=>array(':period'=>Yii::app()->params['locationsGracePeriod']),
			'with'=>array(
				'idCountry'=>array('select'=>''),
				'idState'=>array('select'=>''),
				'idCity'=>array('select'=>''),
			),
		),
		'sort'=>array(
			'attributes'=>array(
				'lid'=>array('asc'=>'t.id', 'desc'=>'t.id DESC', 'label'=>'Id'),
				'lname'=>array('asc'=>'lname', 'desc'=>'lname DESC', 'label'=>'Name'),
				'gracePeriod'=>array('asc'=>'gracePeriod', 'desc'=>'gracePeriod DESC', 'label'=>'Ends in .. days'),
				'coname'=>array('asc'=>'coname', 'desc'=>'coname DESC', 'label'=>'Country'),
				'sname'=>array('asc'=>'sname', 'desc'=>'sname DESC', 'label'=>'State'),
				'cname'=>array('asc'=>'cname', 'desc'=>'cname DESC', 'label'=>'City'),
			),
			'defaultOrder'=>array('gracePeriod'=>CSort::SORT_ASC)
		),
		'pagination'=>array('pageSize'=>20),
	)
);

Inside the view:

$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$locationsProvider,
	'columns'=>array(
		'lname',
		'gracePeriod',
		'coname',
		'sname',
		'cname'
	)
));

The gridview shows no rows, although the headers and sort functionality seems to be there. Obviously, I'm missing something here. Can you help?
... Morpheus: What is "real"? How do you define "real"? If you 're talking about what you can feel, what you can smell, what you can taste and see, then "real" is simply electrical signals interpreted by your brain...
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 12 February 2013 - 05:26 AM

Dear Friend

Did you make all these derived properties as virtual properties.
public $lname;
public $gracePeriod;
public $coname;
public $sname;
public $cname;

//make them safe on search...
public function rules()
	{
		
		return array(
			array('name', 'required'),
		...........................................................
			array('id, lname,gracePeriod,coname,sname,cname', 'safe', 'on'=>'search'),
		);
	}


If you have already done that, I am not having any clue.

Regards.
1

#3 User is offline   GoofyX 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 180
  • Joined: 15-April 09
  • Location:Thessaloniki, Greece

Posted 12 February 2013 - 05:49 AM

Yes, this works, thank you very much. CGridView with the data providers has given me headaches now and then.

All the best. :)
... Morpheus: What is "real"? How do you define "real"? If you 're talking about what you can feel, what you can smell, what you can taste and see, then "real" is simply electrical signals interpreted by your brain...
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