Hi everybody,
I have a real problem to develop good CGridView especially the filters.
My app have 3 tables:
Project
id
name
Component
id
name
projectId
Equipment
id
name
componentId
I would like to have a CGridView on the index of Equipment that show these 3 column :
Identifier (concatenate all three id together) - Project name - Component name - Equipment name
111 - Project 1 - Component 1 - Equipment 1
112 - Project 1 - Component 1 - Equipment 2
…
And I would like to have for all the column a CHtml::listData as filter
Can someone help me to do this ?
Thanks
Here some try :
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'equipment-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'selectableRows' => 1,
'selectionChanged' => 'function(id){ location.href = "' . $this->createUrl('view') . '/id/"+$.fn.yiiGridView.getSelection(id);}',
'columns'=>array(
array(
'header' => 'projectId',
'filter' => CHtml::listData(Project::model()->findAll(), 'id', 'name'),
,
array(
'name' => 'componentId',
'filter' => CHtml::listData(Component::model()->findAll, 'id', 'name',
'value' => 'Equipment::Model()->Find("componentId = ".$data->componentId)->name',
),
array(
'name' => 'equipmentId',
'filter' => CHtml::listData(Equipment::model()->findAll, 'id', 'name'),
'value' => 'Equipment::Model()->FindByPk($data->id)->name',
),
),
?>