Hi, Sorry for my english
I’ve CGridView. When I use filter or sort, its very good. But when I use filter and sort together, filter not found. Filter doesn’t tranfer data. I don’t know why.
This is my search()
public function search()
{
$sort = new CSort;
$sort->defaultOrder = 't.id desc';
$sort->attributes = array(
'domain'=>'domain',
'price'=>'price',
'cus_id' => array(
'asc'=>'cusname',
'desc'=>'cusname DESC',
),
'ser_id'=>'ser_id',
'iduser'=>'iduser',
'startdate'=>'startdate',
'findate'=>'findate',
);
$criteria=new CDbCriteria;
$criteria->together = true;
$criteria->with = array('cus',"user");
$criteria->compare('id',$this->id);
if($this->ser_id!=''){
if(in_array($this->ser_id,Service::getListServiceByParent() ))
$criteria->compare('ser_id',$this->ser_id);
else{
$listchild=Service::getListChild($this->ser_id);
$criteria->addCondition("ser_id in $listchild");
}
}
else $criteria->compare('ser_id',$this->ser_id);
$criteria->compare('cusname',$this->cus_id,true);
$criteria->compare('findate',$this->findate);*/
$startdate=$this->startdate;
$startdate = preg_replace('/^(\d{1,2})-(\d{1,2})-(\d{2,4})$/',"$3-$2-$1",$startdate);
$findate=$this->findate;
$findate = preg_replace('/^(\d{1,2})-(\d{1,2})-(\d{2,4})$/',"$3-$2-$1",$findate);
if($this->startdate!='')
$criteria->addCondition("startdate= '$startdate'");
if($this->findate!='')
$criteria->addCondition("findate= '$findate'");
$criteria->compare('price',$this->price,true);
$criteria->compare('domain',$this->domain,true);
$criteria->compare('username',$this->iduser,true);
$criteria->compare('note',$this->note);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,'sort'=>$sort,
'pagination' => array(
'pagesize' => Yii::app()->params['defaultPageSize'],
)
));
}
And view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'cat-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'afterAjaxUpdate'=>"function() {
jQuery('#".CHtml::activeId($model, 'startdate')."').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['vi'], {'showAnim':'fold','dateFormat':'dd-mm-yy','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#".CHtml::activeId($model, 'findate')."').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['vi'], {'showAnim':'fold','dateFormat':'dd-mm-yy','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
}",
'columns'=>array(
array('header'=>'STT',
'value'=>'++$row',
'htmlOptions'=>array(
'width'=>'40px'
)
),
array(
'name'=>'cus_id',
'filter'=>false,
'value'=>'CHtml::link(Customers::getName($data->cus_id), Yii::app()->createUrl("cusservice/view",array("id"=>$data->id)), array("style" => "font-weight: bold;"))',
'type'=>'raw',
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;width:240px'),
),
array(
'name'=>'ser_id',
'filter'=>Service::getFilterServiceDDL(),
'value'=>'CHtml::link(Service::getName($data->ser_id), "#", array("style" => "font-weight: bold;"))',
'type'=>'raw',
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;width:150px'),
),
array(
'name'=>'price',
'value'=>'$data->price',
'type'=>'raw',
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;text-align: right;'),
),
array(
'name'=>'domain',
'value'=>'$data->domain',
'type'=>'raw',
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;'),
),
array(
'name'=>'iduser',
'value'=>'User::getName($data->iduser)',
'type'=>'raw',
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;'),
),
array(
'name'=>'startdate',
'value'=>'date("d-m-Y",strtotime($data->startdate))',
'type'=>'raw',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'startdate',
'options'=>array(
'showButtonPanel'=>false,
'changeYear'=>true,
'changeMonth'=>true,
'changeDay'=>true,
'dateFormat'=>'dd-mm-yy',
),
),
true
),
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;text-align: right;'),
),
array(
'name'=>'findate',
'value'=>'date("d-m-Y",strtotime($data->findate))',
'type'=>'raw',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'findate',
'options'=>array(
'showButtonPanel'=>false,
'changeYear'=>true,
'changeMonth'=>true,
'changeDay'=>true,
'dateFormat'=>'dd-mm-yy',
),
),
true
),
'htmlOptions'=>array('style'=>'font-weight: bold; color: #0012bd;text-align: right;'),
),
array(
'class'=>'CButtonColumn',
'header'=>'Update',
'template' => '{update}',
'htmlOptions'=>array('style'=>'text-align: center; width: 35px;'),
),
array(
'class'=>'CButtonColumn',
'header'=>'Delete',
'template' => '{delete}',
'htmlOptions'=>array('style'=>'text-align: center; width: 35px;'),
),
),
)); ?>
And Controller
public function actionIndex()
{
$model=new Cusservice('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Cusservice']))
$model->attributes=$_GET['Cusservice'];
$this->render('admin',array(
'model'=>$model,
));
}
PLZ tell me how to fix?