Can you please let me know how to export jquery grid to excel. In the Media Items section there is a video which explains how to export to excel by calling the DB again. But i want to export the contents of the grid to excel. It will be great if some one can assist me on the same.
Regards,
Suresh A
Hi Suresh A,
Thank you for posting in the community.
The Infragistics Excel engine can be used to export the data bound to the igGrid to Excel. Currently there is no separate control for exporting our jQuery grid. You can find more information on the topic in the following discussion:
http://forums.infragistics.com/forums/p/64055/324125.aspx
Here is also a sample from our samples collection demonstrating the Infragistics Excel Framework:
http://samples.infragistics.com/jquery/infragistics-excel/create-excel-worksheet
Please feel free to contact me if you have any questions.
Please do not hesitate to contact me if you have any further questions regarding this scenario.
All the example talks about doing another DB call and then create workbook and populate data to the work sheet. What i was looking for is without any DB call i just want to export the iGrid contents to excel. Is there any ways to achieve this?
Hello Suresh A,
In order not to make consequent query to the database when exporting igGrid data you can cache the data on the server. Use ASP.NET caching (Application caching) for this purpose: http://msdn.microsoft.com/en-us/library/6hbbsfk6(v=vs.100).aspx
When getting the data to populate the grid just add the following line:
// This line adds myIgGridData(which holds Ienumerable) to the cache for 5 minutes Cache.Insert("igGridDataForPrint" + Session.SessionID, myIgGridData, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
// This line adds myIgGridData(which holds Ienumerable) to the cache for 5 minutes
Cache.Insert("igGridDataForPrint" + Session.SessionID, myIgGridData, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
Note that this data is on per session basis, because we don't want different users to overlap each other data. You may want to use other logic to construct the key for the cache.
Then when printing just get the data from the cache like this:
IEnumerable myData = (IEnumerable)Cache["igGridDataForPrint" + Session.SessionID]; if (myData != null) { // export to excel here }
IEnumerable myData = (IEnumerable)Cache["igGridDataForPrint" + Session.SessionID];
if (myData != null)
{
// export to excel here
}
Hope this helps,
Martin Pavlov
Infragistics, Inc.
Hi Martin,
Thanks for your response.
So theres no othey way of doing this??? Like in normal GridView if we use Innerhtml then we can write the contents of the grid. Is there any other way to achieve the same functionality in iGrid as well?
Of course there are other ways to do this, but each of them has its pros and cons.
The pros of my proposal are that it is bandwidth friendly, but the cons is that it takes server memory for the cache.
Another solution is to send igGrid data source(For example plain HTML or JSON) back to the server for processing, but this means that client must upload a lot of data to the server.
About GridView. You can get igGrid Html with this jQuery API:
var gridHtml = $("#grid1").html();
P.S.: I'm not quite sure that I understood your last question. Do you want to skip posting back to the server when exporting to excel or you want to send grid html to server?
Sincerely,
I want to export grid html to excel.
Files cannot be created directly on the client, without using a third party plugin such as Flash, ActiveX or Silverlight. This is a limitation in the way Javascript executes, and this is basically completely sandboxed. Moreover, even if you generate the binary file contents in JavaScript, by following the binary pattern in a string form (quite a lot of work in the first place), you won't be able to serve that file for download directly.
What you can do, though, is generate the file contents on the client, then POST to a URL, and have that URL serve the file to the client.
Download an Excel or any other file from a grid, is not possible without a request to a server, which would serve that file.
there is also a HTML5 API you may take a look at, but it's at an experimental stage:
http://dev.w3.org/2006/webapi/FileAPI/
http://www.w3.org/TR/file-writer-api/
at the moment, AFAIK, only Chrome and FF support this.
Hope it helps. Thanks,
Angel
As far as I know you cannot create file in excel format on client (browser), because there is automation involved in the process etc.
However you can create comma separated file(CSV), which excel can read. Here is Stackoverflow question on the subject:
http://stackoverflow.com/questions/4639372/export-to-csv-in-jquery
Look at the verified answer. There is mentioned "Downloadify" (which you can find here: https://github.com/dcneiner/Downloadify ). You can use it to save a file on the client i.e. popup file save dialog. You have to supply the content yourself by converting igGrid html data into comma separated text.
I haven't done this myself, so I cannot give you sample, but if you experience problems I can try to create one.
Martin Pavlov,