It seems all the filter inputs are empty. Have you actually put data in?
Can you also inspect the page and see if there are any JS errors.
If you can put the page online, that would be helpful as well.
It seems all the filter inputs are empty. Have you actually put data in?
Can you also inspect the page and see if there are any JS errors.
If you can put the page online, that would be helpful as well.
v1.1 is uploaded and adds RTL support. Please see extension homepage or Github repository.
A fellow Github member contributed with that feature / option which I’ve merged into tlbExcelView’s repository.
Was this solved? I am having similar problems.
Error 404:
The system is unable to find the requested action "Admin?".
Hello davelaser
Was what solved?
Please post your controller + view codes
Cheers
When I click the export button I get the message:
ERROR 404
The system is unable to find the requested action "admin?".
Here’s what I have for code. Thanks!
Controller Code
public function actionAdmin()
{
$model=new Weeklyservicereport('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Weeklyservicereport']))
$model->attributes=$_GET['Weeklyservicereport'];
//new stuff for excel export
if(isset($_GET['export'])){
$production = 'export';
}else{
$production = 'grid';
}
$this->render('admin', array('model' => $model, 'production' => $production));
/*before excelview
$this->render('admin',array(
'model'=>$model,
));
*
*/
}
View Code
<div class="row buttons">
<?php echo CHtml::button(Yii::t('app', 'Export to Excel (xls)'), array('id' => 'exportToExcel')); ?>
</div>
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id'=>'weeklyservicereport-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'CompName',
'ShipCity',
'Contact',
'Model',
'esl_SN',
'ServDate',
'ServDate2',
'ServiceEmployee',
'ServDesc',
/*
'ServOnSite',
'ei_SN',
'ei_LocID',
'cl_LocID',
'cl_CompID',
'cn_CompID',
*/
),
)); ?>
I imagine you have a partial view rendered somewhere, and a registered script for the [font="Courier New"]exportToExcel[/font] button? Could you also post them it?
EDIT
You’re also missing this line
'grid_mode' => $production,
Thanks for being patient with me
I don’t think I have a partial view rendered, but here’s the export script.
Script:
$('#exportToExcel').click(function(){
window.location = '". $this->createUrl('admin') . "?' + $(this).parents('form').serialize() + '&export=true';
return false;
});
I’m sorry but I edited my post before yours, what about the missing line?
Also, normally the script should be registered by Yii:
<?php Yii::app()->clientScript->registerScript('search', "
$('#exportToExcel').click(function(){
window.location = '". $this->createUrl('admin') . "?' + $(this).parents('form').serialize() + '&export=true';
return false;
});
"); ?>
Ok, the script is registered I just left out that line. I added the missing line you suggested, and i’m still getting the same result.
Can you put that app online, at least that controller and view?
Is it a problem that I am not using the "Advanced Search" form for entries and just the gridview ? It looks like this may be meant for the search form, but the data exported should still be the same.
View and controller as requested.
View:
<?php
/* @var $this WeeklyservicereportController */
/* @var $model Weeklyservicereport */
$this->breadcrumbs=array(
'Weeklyservicereports'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Weeklyservicereport', 'url'=>array('index')),
array('label'=>'Create Weeklyservicereport', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('#exportToExcel').click(function(){
window.location = '". $this->createUrl('admin') . "?' + $(this).parents('form').serialize() + '&export=true';
return false;
});
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#weeklyservicereport-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Service Report</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<div class="row buttons">
<?php echo CHtml::button(Yii::t('app', 'Export to Excel (xls)'), array('id' => 'exportToExcel')); ?>
</div>
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id'=>'weeklyservicereport-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'grid_mode' => $production,
'columns'=>array(
'CompName',
'ShipCity',
'Contact',
'Model',
'esl_SN',
'ServDate',
'ServDate2',
'ServiceEmployee',
'ServDesc',
/*
'ServOnSite',
'ei_SN',
'ei_LocID',
'cl_LocID',
'cl_CompID',
'cn_CompID',
*/
),
)); ?>
Controller:
<?php
class WeeklyservicereportController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column1';
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Weeklyservicereport;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Weeklyservicereport']))
{
$model->attributes=$_POST['Weeklyservicereport'];
if($model->save())
$this->redirect(array('view','id'=>$model->esl_SN));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Weeklyservicereport']))
{
$model->attributes=$_POST['Weeklyservicereport'];
if($model->save())
$this->redirect(array('view','id'=>$model->esl_SN));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Weeklyservicereport');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Weeklyservicereport('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Weeklyservicereport']))
$model->attributes=$_GET['Weeklyservicereport'];
//new stuff for excel export
if(isset($_GET['export'])){
$production = 'export';
}else{
$production = 'grid';
}
$this->render('admin', array('model' => $model, 'production' => $production));
/*before excelview
$this->render('admin',array(
'model'=>$model,
));
*
*/
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Weeklyservicereport the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=Weeklyservicereport::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param Weeklyservicereport $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='weeklyservicereport-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
Your case is at least different in that there’s no form so no need to send the serialized form data.
You’ll have to be are able to provide an online testing page or the Firebug console output if you’d like me to debug your code. A 404 error means not found resource (url), and I doubt the above is the only reason it doesn’t work. Maybe you have some settings in your URL manager or you can try with [font=“Courier New”]$this->createUrl(‘controller/action’)[/font]
That said, you can see how it works without the form is this fiddle: http://jsfiddle.net/tellibus/emzhQ/, and your problem does not seem consistent. But obviously you should slightly adapt your JS code to remove the serialize and the ‘&’ part.
Thanks again for all of your help.
I haven’t done much with Firebug. Just downloaded FF and installed it. What exactly would you need to help you debug? The console is currently giving me one error when I hit the export button.
"NetworkError: 404 Not Found - http://localhost/ecc2/index.php?r=Weeklyservicereport/admin?&export=true"
Let me know what else would help.
Hmm so you’re not in url path mode. I should have said so in the extension page, sorry for that!
So in your case, you should resolve the issue by one of two methods: setting the [font=“Courier New”]urlFormat[/font] to [font=“Courier New”]‘path’[/font] OR by changing your view code to:
Yii::app()->clientScript->registerScript('search', "
$('#exportToExcel').click(function(){
// If your urlFormat is set to 'path'
// window.location = '". $this->createUrl('admin') . "?' + $(this).parents('form').serialize() + '&export=true';
// Otherwise:
window.location = '". $this->createUrl('admin') . "&export=true';
// Comment the above lines and uncomment the following one if you have a search form and your urlFormat is NOT 'path':
// window.location = '". $this->createUrl('admin') . "&' + $(this).parents('form').serialize() + '&export=true';
return false;
});
");
Thanks Bennouna!
This was exactly the issue. You’re a genius!
Now it appears that the export button is trying to send ALL of the results instead of the results AFTER the search filters are applied.
I feel like I’ve seen this issue before but I couldn’t find it on the forum, are you aware of a fix for this?
Thanks again.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in C:\xampp-portable\htdocs\ecc2\protected\extensions\phpexcel\Classes\PHPExcel\Style\Supervisor.php on line 123
Not exactly sure what was happening, but I’ve managed to fix this. I had to put the button inside of the __search form to get it to export properly. I had it between the search form and the DataGrid which was causing an error.
Hello again,
Is there a way to do more detailed formatting in tlbExcelView?
I’d like to add images and display data similar to something like this.
PHPExcel Demo
Hello.
A way would be to fork the widget and code everything you need.
But personally, I use the PDF format for invoices, and I don’t use CGridView as an output: I put the needed format in a view, and I render it as a PDF. If it’s an option for you, you can see what http://mpdf1.com (for example) can do. It even has an extension : http://www.yiiframework.com/extension/pdf