Yii Framework Forum: GridView filter - change input text filed to dropdown - Yii Framework Forum

Jump to content

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

GridView filter - change input text filed to dropdown Can't find any info on how to do that Rate Topic: -----

#1 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 13 April 2010 - 07:00 AM

Good day to all Yii-fellows!

I'm using CGridView for displaying and filtering data, and it's basic functions work fine,
but I need more ::)

Ok, so in the grid view column-based filtering, each data column by default will display a text field for filtering purposes, but I need some of them to be dropdown lists. For example, "sex" column in Users model is either 0, 1 or 2 (unknown\male\female), so I'd realy like filter column to have simple dropdown instead of text field, because it might become a usability disaster to have to know to type "2" if you're looking for female users.

Didn't found anything on that topic yet :huh: Help, please! ::)
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 13 April 2010 - 07:18 AM

Check the filter propery of CDataColumn - http://www.yiiframew...n#filter-detail
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 13 April 2010 - 07:20 AM

*
POPULAR

Thanks, now I got it!

For those in need :)
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'user-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'id',
		'display_name',
		'email',
		array(
			'name' => 'joined',
			'value' => 'date("d.m.Y",strtotime($data->joined))',
		),
		array(
			'name'=>'sex',
			'filter'=>array(1=>'Guys', 2=>'Girls'),
		),
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>

5

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