Good day guys please help me with my problem I have here a situation that will export a filtered data to excel but when i clicked the button it doesnt export but when i tried delete the export code to alert the data to check if the data was successfully posted it alerted back upon successful.
This is the button that will post the date range to be filtered
echo(CHtml::link('Export to Excel', "",
array(
'style'=>'cursor: pointer;',
'onclick'=>"{catchData();}")
));
?>
<script>
function catchData(){
var fdate = $('#dufrom').val();
var ldate = $('#duto').val();
$.ajax({
type: 'POST',
data: {fdate : fdate, ldate : ldate},
url: '<?php echo CController::createUrl('dutyReport/export'); ?>',
//success: function(data){ alert(data); }
})
}
</script>
this is the controller that will export the filtered date range to excel
public function actionExport()
{
$fdate = $_POST['fdate'];
$ldate = $_POST['ldate'];
echo $fdate,$ldate;
// Load data (scoped)
$criteria = new CDbCriteria;
$criteria->condition = 'duty_date BETWEEN '.$fdate.' AND '.$ldate;
$model=ShisDuty::model()->findAll($criteria);
// Export it
$this->toExcel($model,
array(
'duty_id::#',
'duty_date::Date',
'duty_time_in::Time-in',
'duty_time_out::Time-out',
'dutyFullname.dr_fullname::Doctor',
'dutyReliever.dr_fullname::Reliever',
),
'Duty Report',
array(
'creator' => 'Jimuel',
),
'Excel2007'
);
}