I was having the same confusion with trying to figure out how to get the filterSelector attribute to work. I got something working, so thought i’d post incase it can help others that end up here looking for answers like I did. I found that I could set a filter selector, but since the default filters inputs were being rendered, my custom filter input was not working. What I ended up doing was extending the CGridView class and altering the renderFilters method to check for a new constant so I could exclude the defaults.
Yii::import('zii.widgets.grid.CGridView');
class GridView extends CGridView
{
const FILTER_POS_HIDDEN='hide';
public function init()
{
parent::init();
}
public function renderFilters()
{
if($this->filterPosition===self::FILTER_POS_HIDDEN)
return;
parent::renderFilter();
}
}
Then when I want to render the GridView widget, I pass in the filterSelector as well as a filterPosition set to ‘hide’. After that, I can insert my textfield where ever and it will work. So my view looks something like
$dataArray = array(
'id' => 'user-gridview',
'filter' => $model,
'filterPosition' => 'hide',
'filterSelector' => '#email-filter',
'columns' => $columns,
'template' => "{items}\n{pager}",
'dataProvider' => $dataProvider,
'itemsCssClass' => 'table table-bordered table-striped table-hover',
'selectableRows' => 2,
);
?>
<div class="col-md-12">
<?php echo CHtml::textField('User[email]','',array('id' => 'email-filter', 'class' => 'form-action')); ?>
<?php $this->widget('app.widgets.GridView.GridView', $dataArray); ?>
</div>
Without documentation, it was the best I could figure out. Maybe there is a much simpler way.