filters in gidview

can the filter position be placed outside the grid view?

Yes of corse.

Take a look at the gii generated code for admin: there are some extra filed for search outside, you can see them by clicking on the button "search"

I dint get u…canu be more clearer plzz…

In a gii generated admin you have:

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(


)); ?>

</div><!-- search-form -->

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







The renderPartial(’_search’ renders a view with search field, as you need.

Giving a deeper look at it:

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

    <div class="row">

        <?php echo $form->label($model,'id'); ?>

        <?php echo $form->textField($model,'id'); ?>


    <div class="row">

        <?php echo $form->label($model,'type'); ?>

        <?php echo $form->textField($model,'type',array('size'=>34,'maxlength'=>34)); ?>


    <div class="row">

        <?php echo $form->label($model,'town'); ?>

        <?php echo $form->textField($model,'town'); ?>


    <div class="row buttons">

        <?php echo CHtml::submitButton('Search'); ?>


<?php $this->endWidget(); ?>

</div><!-- search-form -->

You can use this code as a sample. You have to create a get form wich submits the field you want in search, and that’s all.

If you want to do it with js, in the view admin there is once again the line you need:

$('.search-form form').submit(function(){

    $.fn.yiiGridView.update('rent-grid', {

        data: $(this).serialize()


    return false;


This javascript will make so that a post in the search form will cause an ajax update in the datagrid.

The gii generated code is a very good starting point for develop with yii, is really worthwhile to study it deeply.

thanx for you reply but i have gone through it already…but what i need is lil different…i mean i need a label with dropdown with list of options(which are attributes that can be searched in grid view)and after selecting a field one more search label for entering a value(which is somwthing like filters label in gridview)and a search button…

what i finally need is…the filter search button present in a grid view to be placed outside of it…but in the same view

instead of multiple search labels for multiple attributes…i need onlyone search label…


a bit OT… there is no need to quote all the post… especially if you post after it… it’s assumed you are responding to the last post… you made here two posts… both quoting a very long post so it’s very hard to follow this thread… and a user need to scroll (and scroll, and scroll) to be able to read your post…

As for your problem… it can be done… but it’s not easy and you need to code everything…

If you want the filter to be outside the gridview… you can put an active form before the gridview (or anywhere else)…

you just need to call the $model->search() to generate the proper search criteria (or some custom method)… and you need to call $.fn.yiigridview.update() to update the gridview… so that the filtered data is show…