Dear DerekC
I have three approaches. I do not know which one fits your taste.
Let us assume two models. Item,Brand.
table item : id,name,b_id.
table brand : id,name.
Item.php
public function relations()
{
return array(
'brand' => array(self::BELONGS_TO, 'Brand', 'b_id'),
);
}
1.In our first approach we can display the filter.But we are displaying the column without values.
But it is not nice looking.
views/item/admin.php
'columns'=>array(
'id',
'name',
array(
'name'=>'b_id',
'value'=>'',
'filter'=>CHtml::listData(Brand::model()->findAll(),'id','name'),
),
2.In second approach we are going to modify the advanced search form in such a way that
it is going to contain only the element for b_id.
views/item/_search.
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<?php
/* Disable id and name.Display only field for b_id.
<div class="row">
<?php echo $form->label($model,'id'); ?>
<?php echo $form->textField($model,'id'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'name'); ?>
<?php echo $form->textField($model); ?>
</div> */
?>
<div class="row">
<?php echo $form->label($model,'b_id'); ?>
<?php echo $form->dropDownList($model,'b_id',CHtml::listData(Brand::model()->findAll(),'id','name')); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
<?php
/* @var $this ItemController */
/* @var $model Item */
$this->breadcrumbs=array(
'Items'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Item', 'url'=>array('index')),
array('label'=>'Create Item', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('item-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Items</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<? //change the display to block.
php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:block">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'item-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
3.In third approach if we do not want to disturb the the alredy existing advanced search
we can do the following.
views/item/admin.php
<?php
/* @var $this ItemController */
/* @var $model Item */
$this->breadcrumbs=array(
'Items'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Item', 'url'=>array('index')),
array('label'=>'Create Item', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('item-grid', {
data: $(this).serialize()
});
return false;
});
$('#subForm form').submit(function(){
$.fn.yiiGridView.update('item-grid', {
data:{'Item[b_id]':$('#subForm #Item_b_id').val()}
});
return false;
});
");
?>
<h1>Manage Items</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<div id="subForm" style="margin-top:10px;">
<form>
<div class="row">
<?php echo CHtml::activeLabel($model,'b_id'); ?>
<div><?php echo CHtml::activeDropDownList($model,'b_id',CHtml::listData(Brand::model()->findAll(),'id','name')); ?></div>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
</form>
</div><!-- subForm -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'item-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
in third approach essentially we have added a form inside the admin.php and also registered a script to get the value from the form and to update the grid by ajax.
I hope I helped a bit.
Regards.