I was playing with the export functionality today and was amazed that there was not a method that allowed you to set the actual excel filename… all exported files were named grid.xslx
To resolve this oversight just modify a few lines of code as such:
- call function and pass through desired variables
MyGrid.toExcel('./codebase/generate.php?title='+printViewTitle+'&filename='+title);
In this case I am passing both the tab title and filename through.
- Modify the file ‘gridExcelWrapper.php’ starting around line 230 you will see the ‘outXLS’ public function. add the parameter fileName.
public function outXLS($title, $type = 'Excel2007', $fileName) {
-
also change the following 3 lines of code for each file type just below this to the following.
XLS:header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');
CSV:header("Content-Disposition: attachment; filename=".$fileName.".csv");
XLSX:header('Content-Disposition: attachment;filename="'.$fileName.'.xlsx"');
-
Modify the file ‘gridExcelGenerator.php’ and around line 227 you will see
$this->wrapper->outXLS($this->title, $this->outputType)
change to this
$this->wrapper->outXLS($this->title, $this->outputType, $this->fileName)
- up near the top of this same file between lines 28 & 36 add the following line
public $fileName = 'grid';
and thats it… I’m must say that I’m not the worlds best coder so if there is a better solution please feel free to correct me… but this does work and does not corrupt the exported file format.
I hope this can help someone and maybe in the next version they will actually implement this or a better solution…