Hi, i am new and want to learn export to Excel filtered gridview results using gridview top filter row .
I want to export like this gridresult:
4340
is it possible and if so can anyone give an example please.
Thanks from now.
Hi, i am new and want to learn export to Excel filtered gridview results using gridview top filter row .
I want to export like this gridresult:
4340
is it possible and if so can anyone give an example please.
Thanks from now.
Ok i solved,
with this way:
public function actionAdmin() {
$model=new Customer('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Customer']))
$model->attributes=$_GET['Customer'];
Yii::app()->user->setState('exportModel',$model); //this can be any other storage
$this->render('admin',array(
'model'=>$model,
));
}
public function actionExportToFile() {
//echo 'test';
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="report-customers-' . date('YmdHi') .'.csv"');
$model=new Customer('search');
$model->unsetAttributes(); // clear any default values
if(Yii::app()->user->getState('exportModel'))
$model=Yii::app()->user->getState('exportModel');
$dataProvider = $model->search(false);
// csv header
echo Customer::model()->getAttributeLabel("Id").",".
Customer::model()->getAttributeLabel("Country_Id").",".
Customer::model()->getAttributeLabel("Gender_Id").",".
Customer::model()->getAttributeLabel("First_Name").",".
Customer::model()->getAttributeLabel("Last_Name").
" \r\n";
// csv data
foreach ($dataProvider->getData() as $data) {
echo "$data->Id, $data->Country_Id, $data->Gender_Id, $data->First_Name, $data->Last_Name \r\n";
}
exit;
}
Hi
When I export to csv file its gives me only first page results . I need all search results to be in my CSV
Thanks in advance
Janaka
I did what you posted, but what it does is show the result, not download the public look at the code result
public function actionReporte() {
$bus = true;
if (!isset($_POST['fechaini']) || $_POST['fechaini'] == "") {
if (!isset($_POST['fechafin']) || $_POST['fechafin'] == "") {
$bus = false;
}
}
if ($bus == true) {
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="report-customers-' . date('YmdHi') . '.csv"');
$criteria = new CDbCriteria();
$criteria->addBetweenCondition("Fecha_cita", $_POST['fechaini'], $_POST['fechafin']);
$criteria->addCondition('personal="no"');
$citas = Calendario::model()->findAll($criteria);
Yii::app()->user->setState('exportModel',$citas);
if (Yii::app()->user->getState('exportModel'))
$citas = Yii::app()->user->getState('exportModel');
$dataProvider = new CArrayDataProvider($citas);
foreach ($dataProvider->getData() as $data) {
echo "$data->Fecha_cita, $data->Hora_inicial,
$data->Servicio, $data->Nombre_completo \r\n";
}
exit;
} else {
throw new CHttpException(500, 'Faltan Parametros');
}
}
y esto es mi vista
<div id="resultado">
<?php echo TbHtml::textField('fechaini', '', array("style" => "margin-bottom: 5px;")) . ' Hasta: ' . TbHtml::textField('fechafin', '', array("style" => "margin-bottom: 5px;")); ?>
<?php
echo TbHtml::submitButton(TbHtml::icon(TbHtml::ICON_DOWNLOAD_ALT) . 'Generar', array('color' => TbHtml::BUTTON_COLOR_WARNING,
"ajax" => array(
"type" => "post",
"url" => Yii::app()->createUrl("admin/calendario/reporte"),
"data" => array(
"fechaini" => "js:$('#fechaini').val()",
"fechafin" => "js:$('#fechafin').val()"
),
"success" => "function(data){
$('#reporte').html(data);
}",
"error" => "function(data){
$('#reporte').html('');
}",
)
))
?>
<div id="reporte">
<?php $this->renderPartial('reporte'); ?>
</div>
</div>
thank so they can work me, thanks
This…worked perfect for me… Thanks…