this is the code for the filter in model
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('duty_id',$this->duty_id);
$criteria->compare('duty_date',$this->duty_date,true);
$criteria->compare('duty_time_in',$this->duty_time_in,true);
$criteria->compare('duty_time_out',$this->duty_time_out,true);
$criteria->compare('duty_fullname',$this->duty_fullname);
$criteria->compare('duty_reliever',$this->duty_reliever);
//$criteria->compare('duty_date',$this->date_first);
//$criteria->compare('duty_date',$this->date_last);
if((isset($this->date_first) && trim($this->date_first) != "") && (isset($this->date_last) && trim($this->date_last) != ""))
$criteria->addBetweenCondition('duty_date', ''.$this->date_first.'', ''.$this->date_last.'');
//where duty_date between date_first and date_last
$criteria->order = 'duty_date DESC';
$criteria->with=array('dutyReliever', 'dutyFullname');
$criteria->compare('dutyFullname.dr_fullname',$this->fu_search, true);
$criteria->compare('dutyReliever.dr_fullname',$this->re_search, true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
code for search form
<?php
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
?>
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<table border='0' width="500px" align="center">
<tr>
<td align="center">
<div class="row">
FROM:
<?php
$form->widget('CJuiDateTimePicker',array(
'model'=>$model,
//'name'=>'dufrom',
'attribute'=>'date_first',
'id'=>'dufrom',
'mode'=>'date', //use "time","date" or "datetime" (default)
'language' => '',
'options'=>array('showSecond'=>true,'dateFormat'=>'yy-mm-dd','showButtonPanel'=>true,'changeMonth'=>true,
'changeYear'=>true,'showAnim'=>'fade','showWeek'=>true,
),
'htmlOptions'=>array('readonly'=>'readonly','size'=>'20','style'=>'width:100px;'),
)
);
?>
<?php echo $form->error($model,'date_first', array('style'=>"color:red")); ?>
</div>
</td>
<td align="center">
<div class="row">
TO:
<?php
$form->widget('CJuiDateTimePicker',array(
'model'=>$model,
//'name'=>'duto',
'attribute'=>'date_last',
'id'=>'duto',
'mode'=>'date', //use "time","date" or "datetime" (default)
'language' => '',
'options'=>array('showSecond'=>true,'dateFormat'=>'yy-mm-dd','showButtonPanel'=>true,'changeMonth'=>true,'changeYear'=>true,'showAnim'=>'fade','showWeek'=>true,
//'autoOpen'=>true,'themeUrl' => Yii::app()->baseUrl.'/css','theme'=>'overcast', //try 'bee' also to see the changes
//'cssFile'=>array('jquery-ui-1.8.23.custom.css' /*,anotherfile.css, etc.css*/),
), // jquery plugin options
'htmlOptions'=>array('readonly'=>'readonly','size'=>'20','style'=>'width:100px;'),
)
);
?>
<?php echo $form->error($model,'date_last', array('style'=>"color:red")); ?>
</div>
</td>
</tr>
<tr>
<td align="center">
<div class="row">
<?php echo $form->label($model,'duty_fullname'); ?>
<?php echo $form->dropdownlist($model,'duty_fullname', $model->getDr(), array('prompt'=>'Select Doctor')); ?>
</div>
</td>
<td align="center">
<div class="row">
<?php echo $form->label($model,'duty_reliever'); ?>
<?php echo $form->dropdownlist($model,'duty_reliever', $model->getDr(), array('prompt'=>'Select Doctor')); ?>
</div>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<div class="row">
<?php //echo $form->label($model,'duty_date'); ?>
<?php //echo $form->textField($model,'duty_date'); ?>
</div>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<div class="row buttons">
<?php echo CHtml::submitButton('Generate Report',array('id'=>'button','class'=>'btn btn-success ui-button ui-widget ui-state-default ui-corner-all')); ?>
</div>
</td>
</tr>
</table>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
code for display
<script>
$(document).ready(function(){
$('#report').hide();
$('#button').click(function(){
if($('#dufrom').val() != "" && $('#duto').val() != "")
{
$('#report').show();
}
else
{
alert("Date from/to must not empty");
}
});
$('#dufrom').change(function(){
$('#date_first').val($('#dufrom').val());
});
$('#duto').change(function(){
$('#date_last').val($('#duto').val());
});
});
</script>
<?php
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$this->breadcrumbs=array(
'Shis Duties'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List ShisDuty', 'url'=>array('index')),
array('label'=>'Create ShisDuty', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
$('#shis-duty-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<center>
<div style="width:800px;">
<?php
$this->beginWidget('zii.widgets.CPortlet', array(
'title'=>"<center><h3>Report</h3></center>",
));
?>
<div class="search-form">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<div id="report">
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'shis-duty-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'name'=>'duty_date',
),
array(
'header'=>'Time-in',
'name'=>'duty_time_in',
'value'=>function($data){
if($data->duty_time_in > "12:00")
{
$timeIn = date('h:i', strtotime('-12 hours', strtotime($data->duty_time_in)))." pm";
}
else
{
$timeIn = date('h:i a', strtotime($data->duty_time_in));
}
return $timeIn;
},
'filter'=>CHtml::activeTextField($model,'duty_time_in'),
),
array(
'header'=>'Time-out',
'name'=>'duty_time_out',
'value'=>function($data){
if($data->duty_time_out > "12:00")
{
$timeOut = date('h:i', strtotime('-12 hours', strtotime($data->duty_time_out)))." pm";
}
else
{
$timeOut = date('h:i a', strtotime($data->duty_time_out));
}
return $timeOut;
},
),
array(
'header'=>'Dr. Fullname',
'name'=>'dutyFullname.dr_fullname',
),
array(
'header'=>'Reliever',
'name'=>'dutyReliever.dr_fullname',
'value'=>'($data->dutyReliever !== null) ? $data->dutyReliever->dr_fullname : "N/A"',
),
),
)); ?>
<?php echo CHtml::link('Export to Excel',array('dutyreport/export')); ?>
<script>
function catchData(){
var fdate = $('#dufrom').val();
var ldate = $('#duto').val();
$.ajax({
type: 'POST',
data: {fdate : fdate, ldate : ldate},
url: '<?php echo CController::createUrl('export'); ?>',
})
}
</script>
</div>
<?php $this->endWidget(); ?>
</div>
</center>