Filter Of Gridview In _Form Page Is Not Work

I use gridview to show type of data in _form page for select to update/create in same page.

But gridview is not filtered when click on search button.

this code is Advance Search button at _form page


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

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

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

                            'types'=>$types,

        )); ?>            

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



And this code is _searchType page


  <?php $this->beginWidget('bootstrap.widgets.TbActiveForm',array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

        )); ?>


<?php        Yii::app()->clientScript->registerScript('_searchType', "

                    $('.search-button').click(function(){

                            $('.search-form').toggle();

                            $.fn.yiiGridView.update('#type-grid',{

                                    data : $(this).serialize(),

                                    success: function() {

                                            $.fn.yiiGridView.update('#type-grid');

                                    }

                            });

                            return false;

                    });

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

                            $.fn.yiiGridView.update('#type-grid',{

                                    data : $(this).serialize(),

                                    success: function() {

                                            $.fn.yiiGridView.update('#type-grid');

                                    }

                            });

                            return false;

                    });

                    ");

        ?>


  <?php $this->widget('bootstrap.widgets.TbGridView',array(

                        'id'=>'type-grid',

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

                        'filter'=>$types,

                        'columns'=>array(

                                'id',

                                'code',

                                'name',

                                'description',

                                array(

                                    'name'=>'subTypes',

                                    'value'=>'$data->subTypes->type',),

                                array(

                                    'class'=>'CCheckBoxColumn',   

                                    'id'=>'id',    

                                ),   


                        ),

        )); ?>


	<div class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'click',

			'type'=>'primary',

			'label'=>'Search',

                        ));

                        ?>            


                

	</div>


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



this code is controller


  public function actionIndexS()

	{

		/*comment to not use dataProvider Mode*/

		$types=new Types('search');

		

		$types->unsetAttributes();  // clear any default values

		

		if(isset($_GET['Types']))

			$types->attributes=$_GET['Types'];

		

		

				

		$this->render('_searchTypes',array(

			'types'=>$types,

		));

	}


	public function actionCreate()

	{

		$model = new Bom;

                $type = new Type;

                $types = new Type('search');

                $types->unsetAttributes();  // clear any default values

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);

                if(isset($_GET['Types']))

			$types->attributes=$_GET['Types'];

                

                if(isset($_POST['Bom'],$_POST['Type']))

		{

			$model->attributes = $_POST['Bom'];

			if($model->save())

                            $this->redirect(array('view','id'=>$model->id));

		}


		$this->render('create',array(

                        'types'=>$types,

                        'type'=>$type,

			'model'=>$model,

		));

                       

	}



this code is search() at Type


 	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('code',$this->code,true);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('description',$this->description,true);

		$criteria->compare('location',$this->location,true);

		$criteria->with = array('subTypes',);

		

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



this code is on create page




<?php echo $this->renderPartial('_form', array('model'=>$model,'type'=>$type,'types'=>$types)); ?>



Have any idea why filter in gridview is not work?

but I use firebug to check the gridview was refresh when I search.

Thank you

Hi tihnov, welcome to the forum.

You can put a CGridView in your form, but you have to render the advanced search form for the grid outside of the main form.

How?

Could you explain more?

Thank for your reply.

Tihnov

Well, I might have misunderstood your code.

This is what your index page is like:




    <form> ... for advanced search

        <div> ... for grid

            grid view

        </div>

    </form>



Am I right? I think it might be working fine …

And, I thought that your create page might be something like this:




    <form> ... for creation

        <form> ... for advanced search

            <div> ... for grid

                grid view

            </div>

        </form>

    </form>



I might be wrong here, but if it is actually the case, then it won’t work properly.

I would construct the index page like the following:




    <form> ... for advanced search

    </form>

    <div> ... for grid

        grid view

    </div>



This is the structure you may see in the gii-generated admin page.

And for create page, I would like to write:




    <form> ... for advanced search

    </form>

    <div> ... for grid

        grid view

    </div>

    <form> ... for creation

    </form>



Or, if I want to use the grid for the tabular input:




    <form> ... for advanced search

    </form>

    <form> ... for creation

        <div> ... for grid

            grid view

        </div>

    </form>