Cgridview Doesnt Export Using Phpexcel

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'

		);

	}



why not using Extensions?

See here and this one specifically

Hi Jimuel,

What do you do in toExcel() method? Creating and saving an excel file in the server side? Or, directly returning the output content?

And what is the expected scenario when the user clicks on ‘Export to Excel’ link? Does he/she get prompted to download the created excel file?

I think you’d be better use a normal link or post instead of an ajax call.

tnx for the reply well for the export to excel method there is a cgridview displayed in the page and then when the button was clicked it will download an excel file. when i use a normal link or post the first and last date doesnt pass to the controller in order to filter the data to export to excel.

i already used an extension but i will try different extension tnx for your advise.