Recently had an issue reported by a long time customer.
While using Export to excel in Htmltreegrid, We have implemented “Excel2007” option to export gridData in “.xls” format.
We are implementing this using Excel2007Exporter.js file(see attached) and added following code in our controller file in onGridCreationComplete function.
$scope.onGridCreationComplete = function(evt) {
var grid = evt.target;
grid.excelOptions.exporters = exporters = [new flexiciousNmsp.CsvExporter(), new flexiciousNmsp.DocExporter(),
new flexiciousNmsp.HtmlExporter(),new flexiciousNmsp.XmlExporter(),new flexiciousNmsp.TxtExporter(),
new flexiciousNmsp.Excel2007Exporter()
];
grid.excelOptions.enableLocalFilePersistence=false;
grid.validateNow();
};
But while Exporting the data of the grid which is having more than large records(1000+ records), It redirects to Flexicious homepage and shows error message whithout generating excel.
Please suggest on this.
=========================================================
Answer :
This customer was using sample code from an old version of the product that did not have support for file saver. It was using the flexicious server echo. When you do a export , we basically build a string on the client application. If Flash player is available, we will use it via the downloadify library. If not, we need to go through the traditional http File Buffering process. So what we do is this : We build the excel/word/html string, and send it to the server, which simply writes it back, in addition to setting the content type. Now, we advise that you implement your own url to buffer this string back, but do provide our own url - the one mentioned above to perform the buffering. There is more information here : http://blog.htmltreegrid.com/post/Excel-Word-and-Html-Export-and-the-Echo-URL.aspx
However, with the newer versions, we have added support for file saver. On modern browsers, you can do file save without the need for having flash. So the download mechanism will check to see if filesaver exists and is supported, if so, will use that. If it is not there or is not supported, it will fall back to flash. All you have to do is to use the new release and include FileSaver.js. If you include our PDF support, FileSaver is automatically included.
<script type="text/javascript" src="http://htmltreegrid.com/demo/external/js/thirdparty/jspdf-combined.js"></script>
You can also import filesaver independently:
https://github.com/eligrey/FileSaver.js/
Complete working example below:
index.zip (2.74 kb)