Question

Here's my situation. I'm developing an ASP.NET (2.0) app for internal use. In it, I've got a number of pages with GridViews. I've included an option to export the data from the GridView to Excel (client-side using Javascript). The Excel workbook has 2 tabs - one tab is formatted like the GridView, the other tab contains the raw data. Everything works great and looks good from the client's standpoint. The issue is that the Javascript is pretty ugly.

When I fill my dataset with the data the GridView is bound to, I also build a delimited string that's used for the export. I store the delimited string in a HiddenField, and retrieve the value of the HiddenField when the export button is pressed. I have several different delimiters, and it generally has that hacked together feel. Is there a better way to store the data for export and is there a more standard method of storing it instead of a roll-your-own delimited string? I haven't dug into JSON yet. Is this the right path to go down?

Was it helpful?

Solution

JSON is an excellent solution and very fast, although splitting strings is very fast too. You may also want to look into using window.name as a client-based storage solution. The window.name property can easily store a few megabytes worth of data.

I've played around with my own implementation. You "String-ify" your JSON data and stash it in window.name. When your page loads, you grab window.name and "JSON-ify" it, assign it to a JavaScript variable and see if you got what you expected, if not, go grab it from the server via AJAX. I use Prototype for my JSON-string conversion and AJAX, but you can just as easily use jQuery.

http://www.thomasfrank.se/sessionvars.html

OTHER TIPS

I abhor delimited strings, if not the people who rely on them !

JSON is a pretty good bet, though in my opinion an AJAX call to the server to get the converted data might also be worth looking into. You should research your options starting with "Client-side Persistent Data (CSPD)". Here's a JS implementation by Vinu Thomas that simplifies this task (though I haven't tried it)

Additionally, the spec for HTML 5 includes options for DOM based data storage. I think that's so exciting! ;-)

I think the AJAX approach is the best solution, because in many cases (if not most) the export data that is being stored in the DOM won't even be used at all. All users of the page will have to incur the larger slower page download. If you go with the AJAX approach you can keep the page lighter and potentially faster depending on how much extra data is being embedded for exported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top