This is another topic that we get some questions from our customers about:
When the HTMLTreeGrid is used to export data, the file generated can be saved onto the users desktop in one of two ways
- Using the downloadify library, where the file is saved directly on the client (Downloadify internally uses the Flash player plugin)
- Using server buffering - The generated text is sent to the server, and the server buffers it back as a file. The grid has a property, grid.excelOptions.echoUrl - this defaults to http://www.flexicious.com/Home/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. The server side code for this is very simple:
//This is C# code, you could just as easily do the same thing in Java or PHP or whatever it is that sits on your server.
var extension = Request["extension"];
var contentType = Request["contentType"];
var body= Request["body"];
Response.ClearContent();
Response.AddHeader("content-disposition", string.Format("attachment; filename=Download.{0}",extension));
Response.ContentType = contentType;
Response.Write(body);
Response.End();
As always, do not hesitate to reach out if you have any questions.
EDIT : With the new 2.0 release, we have included support for filesaver, so you can have downloads without the need for Flash player.
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/