i’m new in yii framework and i need help to export my grid
i use tlbexcelview, follow the instruction but with a different action, view and create new controller. the result it cant export my grid, only search data.
below is my view, export_excel.php
<?php
/* @var $this SatisfactController */
/* @var $model Satisfact */
$this->breadcrumbs=array(
'Satisfacts'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Satisfact', 'url'=>array('index')),
array('label'=>'Create Satisfact', 'url'=>array('create')),
);
$urljoin= Yii::app()->urlManager->getUrlFormat() == 'path' ? '?' : '&';
Yii::app()->clientScript->registerScript('search', "
$('#exportToExcel').click(function(){
window.location='".$this->createUrl('export').$urljoin."'+
$(this).parents('export_excel').serialize()+'&export=true';
return false;
});
$('.search-form form').submit(function(){
$('#satisfact-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Report </h1>
<div class="well" style="">
<?php $this->renderPartial('_searchex',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id' => 'satisfact-grid',
'dataProvider' => $model->search(),
'grid_mode' => $production, // Same usage as EExcelView v0.33
//'template' => "{summary}\n{items}\n{exportbuttons}\n{pager}",
'title' => 'CS Admin - ' . date('d-m-Y - H-i-s'),
'creator' => 'ATK CS',
'subject' => mb_convert_encoding('Something important with a date in French: ' . utf8_encode(strftime('%e %B %Y')), 'ISO-8859-1', 'UTF-8'),
'description' => mb_convert_encoding('Etat de production généré à la demande par l\'administrateur (some text in French).', 'ISO-8859-1', 'UTF-8'),
'lastModifiedBy' => 'Some Name',
'sheetTitle' => 'Report on ' . date('m-d-Y H-i'),
'keywords' => '',
'category' => '',
'landscapeDisplay' => true, // Default: false
'A4' => true, // Default: false - ie : Letter (PHPExcel default)
'RTL' => false, // Default: false - since v1.1
'pageFooterText' => '&RThis is page no. &P of &N pages', // Default: '&RPage &P of &N'
'automaticSum' => true, // Default: false
'decimalSeparator' => ',', // Default: '.'
'thousandsSeparator' => '.', // Default: ','
//'displayZeros' => false,
//'zeroPlaceholder' => '-',
'sumLabel' => 'Column totals:', // Default: 'Totals'
'borderColor' => '00FF00', // Default: '000000'
'bgColor' => 'FFFF00', // Default: 'FFFFFF'
'textColor' => 'FF0000', // Default: '000000'
'rowHeight' => 45, // Default: 15
'headerBorderColor' => 'FF0000', // Default: '000000'
'headerBgColor' => 'CCCCCC', // Default: 'CCCCCC'
'headerTextColor' => '0000FF', // Default: '000000'
'headerHeight' => 10, // Default: 20
'footerBorderColor' => '0000FF', // Default: '000000'
'footerBgColor' => '00FFCC', // Default: 'FFFFCC'
'footerTextColor' => 'FF00FF', // Default: '0000FF'
'footerHeight' => 50, // Default: 20
'columns' => //'id',
array(
array('header'=>'No','value'=>'++$row',),
//'Nilai Kepuasan',
array('name'=>'message','header'=>'Kritik dan Saran'),
array('name'=>'satisfact01.name','header'=>'Kepuasan'),
array('name'=>'user01.username','header'=>'Customer Service'),
array('name'=>'lokasi'),
array('name'=>'create_date','header'=>'Tanggal',//'value'=>"date('dd-MM-yyyy',CDateTimeParser::parse(\$data->create_date, 'dd-MM-yyyy'))",
'value'=>'Yii::app()->dateFormatter->format("dd-MM-yyyy",$data->create_date)',
), // an array of your CGridColumns
))); ?>
below is my controller
.....
public function actionExport()
{
$model=new Satisfact('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Satisfact'])){
//$model->attributes=$_GET['Satisfact'];
$model->user_id=$_GET['Satisfact']['user_id'];
$model->lokasi=$_GET['Satisfact']['lokasi'];
$model->from_date=$_GET['Satisfact']['from_date'];
$model->to_date=$_GET['Satisfact']['to_date'];
}
if (isset($_GET['Satisfact'])) {
$production = 'export';
} else {
$production = 'grid';
}
$this->render('export_excel',array(
'model'=>$model, 'production'=>$production
));
}
....
this is my _searchex.php
<?php
/* @var $this SatisfactController */
/* @var $model Satisfact */
/* @var $form CActiveForm */
?>
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
'enableAjaxValidation'=>true,
)); ?>
<div class="row">
<?php //echo $form->label($model,'user_id'); ?>
<?php //echo $form->textField($model,'user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php $_u = User::model()->findAll();
echo CHtml::activeDropDownList(
$model,'user_id',
CHtml::listData($_u,'id','username'),
array('prompt'=>'',) //empty is aliases FOR ALL user
);
?>
</div>
<?php echo $form->labelEx($model,'lokasi'); ?>
<?php $lo_u = Lokasi::model('Lokasi')->findAll('id');
echo CHtml::activeDropDownList(
$model,'lokasi',
CHtml::listData($lo_u,'location','location'),
array('prompt'=>'',)//empty is aliases FOR ALL lokasi
);
?>
<div class="row">
<?php //echo $form->label($model,'lokasi'); ?>
<?php //echo $form->textField($model,'lokasi',array('size'=>25,'maxlength'=>25)); ?>
</div>
<div class="column">
<?php echo $form->label($model,'create_date'); ?>
<?php //echo $form->textField($model,'create_date'); ?>
<?php
echo "From : ";
$this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'name'=>'Satisfact[from_date]',
'options'=>array('dateFormat'=>'yy-mm-dd',),
));
echo " To : ";
$this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'name'=>'Satisfact[to_date]',
'options'=>array('dateFormat'=>'yy-mm-dd',),
));
?>
</div>
<div class="row buttons">
<?php //echo CHtml::submitButton('Search'); ?>
<?php echo CHtml::submitButton('Export',array('id' => 'exportToExcel')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
how can I find and to export the data search ?