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