CGridView filter control


(Genady) #1

By default, Grid creates filter control in a form of text box. For one of my columns I want to replace that with

DropDownList selector. How can I do this?

Thanks.


(Omzy83) #2

array(

	'name'=>'attribute',

	'value'=>'$data->attribute',

	'filter'=>array(<data options>),

),


(Omko) #3

For example




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

	'id'=>'properties-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id',

		'title',

		array(

			'name'=>'state_id',

			'value'=>'$data->state->name',

			'filter'=> CHtml::listData(States::model()->findAll(), 'id', 'name'),

		),

		'year_build',

		'city',

		array(

			'name'=>'featured',

			'value'=> $model->featured,

			'filter'=>array(0=>"No", 1=>"Yes"),

		),

		array(

			'name'=>'type_id',

			'value'=>'$data->type->name',

			'filter'=> CHtml::listData(Types::model()->findAll(), 'id', 'name'),

		),

		array(

			'name'=>'listing_type_id',

			'value'=> $model->listing_type_id,

			'filter'=> CHtml::listData(ListingTypes::model()->findAll(), 'id', 'name'),

		),

		'price',

		'user.username',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>




(Jgarcias Cr) #4

Thank you omko. This is the answer I was looking for.

Cheers.


(Sonamaggarwal31) #5

filters are not working please help


(Swisscheese2122) #6

oh man, sorry to hear that!


(Giancarloalbanese 74) #7

Hi,

i have this problem:

an field has this values: (0,1,2,3,4,5)

It’s possible create an filter that show

all records > 0

?


(Giancarloalbanese 74) #8

For to show all records > 0:


'filter'=>array('<1'=>'empty','>0'=>'full'),

but how can I add this item to the following filter?




'filter'=> CHtml::listData(States::model()->findAll(), 'id', 'name'),