hello,
I has tried to modify search in gridview control. refer with this forum http://www.yiiframework.com/forum/index.php?/topic/16603-filters-in-gidview/page__p__82310__hl__grid+view+filter#entry82310
but I still have not managed to filter the data. I really want is the data appear in accordance with the firstname or email (LIKE operator with %).
I have tried like this:
model:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
// $criteria->compare('store_id',$this->store_id);
$criteria->compare('firstname',$this->firstname,true);
$criteria->compare('lastname',$this->lastname,true);
$criteria->compare('email',$this->email,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'pagination'=>array('pageSize'=>5),
'sort'=>array(
'attributes'=>array(
'firstname','groupname','email','date_added','status'
),
),
));
}
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('gridcust', {
data: $(this).serialize()
});
return false;
});
");
?>
<?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 -->
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'id'=>'gridcust',
'filter'=>$model,
'enableSorting'=>true,
'columns'=>array(
array(
'class'=>'TCheckBoxColumn',
'id'=>'chk',
'visible'=>true,
),
array(
'header'=>'Customer Name',
'value'=>'$data[firstname]." ".$data[lastname]',
),
array(
'class'=>'CLinkColumn',
'header'=>'E-mail',
'labelExpression'=>'$data[email]',
'urlExpression'=>'"mailto:".$data[email]',
),
_search.php
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo $form->label($model,'firstname'); ?>
<?php echo $form->textField($model,'firstname'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->