This is another topic that we get some questions from our customers about:

Flexicious, out of the box, offers you the ability to Export the datagrid data to Word, Excel, Html, Text. We also provide a plugin based mechanism, where in you can add your own exporters. The example includes a class, MyDocExporter, which is basically a custom Export plugin. Check it out to see how easy it is.

The question that we get most times however, is when our customers notice the request being sent to http://www.flexicious.com/Home/Echo.

So let us explain whats going on:

When you do a export (or pdf - more on that later), we basically build a string on the client Flex application. Since Flash player (Up until v10) could not write to your hard drive (except shared objects), 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();

And then the final part, of letting the DataGrid know that you have your own server url. To do this, when you call ExportController.export, just pass in MyExportOptions and in the create method, set the echoUrl of the ExportOptions object to your server url.

 

Please note, if you are using Flex 4/Flash Player 10, in MYExportOptions.as, create method, if you set options.enableLocalFilePersistence=true, none of this will be needed, since we will be persisting the file locally without a server round trip.

 

As always, do not hesitate to reach out if you have any questions info at flexicious dot com

=====================================================================

 

Edit:

One of our customers reported a peculiar problem with their implementation of the Echo - it always worked the second time. Below is what they noticed:

·         Problem only occurs in IE (I’m currently using V8) – In Firefox it always works
·         Key Point: Changing your code, CsvExporter.contentType from “application/vnd.ms-excel” to “text/csv” makes it work.
·         It always works using your implementation of Echo on the flexious site.

The issue stumped us as well as them, and they were kind enough to send us the resolution once they found it:
In the handler the following line needs to be added after ClearContent():
context.Response.ClearHeaders();

=====================================================================

Additional information When filterPageSortMode=server:
When filterPageSortMode=server, print/export works a little differently when you select “all pages” or “selected pages”. In this case, you need to wire up the PrintExportDataRequest event

            //This event is only fired when the user requests to print data that is currently
            //not loaded in the grid. It is only applicable when filterPageSortMode is set to
            //'server', because in this mode, the grid only requests the current page of data
            //from the server.
            //For example, if the user asks to print pages 1-4 of a 10
            //page grid, and we're currently on page #4, on the client, we only have the records
            //from page #4. So we have to get the records from pages 1-4 from the server.
            //when this data comes back, we just set the grids.printExportData property, and the
            //print/export mechanism continues as usual.


Review the code here:
http://www.flexicious.com/resources/Flex/srcview/source/com/sample/examples/ServerGridDotNet.mxml.html

This code demonstrates how to handle the printExportDataRequest event, and is heavily commented to explain what is going on.

=====================================================================

 

Changes since 2.0:

Since FP 10 is now more and more common, the default export setting is to use local file persistence. This will cause the grid to issue a call to FileReference.save(). This only exists on FP 10+. For most of our customers, this has been ok, but for some others, who require compatibility for FP 9 this will cause an RTE (ReferenceError: Error #1069: Property save not found on flash.net.FileReference and there is no default value.). To resolve this, either upgrade to FP10, or  set options.enableLocalFilePersistence=false, and either provide your own echo URL as specified above, or you can use our echo.

Also - Since FP 10.1, security was introduced that caused the file download box to break, since it was not instantiated by immediate user action. To this effect, a new property, useSaveFileMessage was introduced in 2.2 to enable the user to click on a button to trigger the download box.