Hello,
I'm trying to use the following sample page to set up a simple Excel export:
http://www.igniteui.com/infragistics-excel/create-excel-worksheet
My goals are the following:
1) When the Export button is clicked, the current page should not have to be re-drawn.
2) The user shouldn't have to be redirected to another window to perform the export.
To achieve those goals, I set up a little ajax call like this when the Export button is pressed:
var grid= $("#igGrid").data("igGrid").dataSource.dataView();
$.ajax({ type: "POST", url: "/Excel/ExcelExport", contentType: "application/json", data: JSON.stringify(grid) });
Everything works fine when the controller receives this post, but when it executes the SendForDownload() method in my controller, no download is actually triggered in the browser. I suspect this is because of the nature of how ajax calls are interpreted by the browser. My SendForDownload() method is almost identical to the sample:
private void SendForDownload(Workbook document, WorkbookFormat excelFormat) { string documentFileNameRoot; documentFileNameRoot = "Document.xlxs"; Response.Clear(); Response.AppendHeader("content-disposition", "attachment; filename=" + documentFileNameRoot); Response.ContentType = "application/octet-stream"; document.SetCurrentFormat(excelFormat); document.Save(Response.OutputStream); Response.End(); }
Am I going about this the right way? I would really appreciate any advice from the support devs on how to achieve this functionality, whereby the user can simply click Export and see a download prompt appear without altering the state of the currently loaded page.
Thank you!
I have the exact same problem as Klye explains in this post and was wondering if there is a way to still send the response back to the client without the caching workaround that Klye used? I have to wait for the user to make their changes to the grid and only then take that data and save it off to Excel. I can get all the data to the server fine using a simple ajax call but I can't get the Reponse.OutputStream back to the client most likely due to the async nature of ajax. Is it possible to simply upload the contents of a iggrid to the server and have the server sendback the stream in the response like the example SendForDownload method does? I have seen other posts from Infragistics members saying that you can send a JSON array of data to the server and have the server send back the xlsx file but no clear complete working example.
We also eventually needed a solution that would allow the user to make edits in the grid and see those changes reflected in the export. We settled on a little utility called jQuery File Download Plugin. Might be worth a try for you:
https://github.com/johnculviner/jquery.fileDownload
You wire up an export button on your page to an ajax call, something like this:
function exportItems() { var items = { items: $('#igGrid').igGrid('option', 'dataSource').Records }; $.fileDownload('Excel/ItemExport', { httpMethod: "POST", data: items });}
Then in your SendForDownload() method, you include this statement:
Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
There are probably many other ways to make this work, but this approach ended up working fine for us.