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!
Hi Troy, thanks for the response. What I'm really trying to get at is the ability to export the contents of the grid without having to repeat the database query which produced the grid in the first place. That seems to be the way it's done in the interactive example.
Since all of the grid rows exist client-side after the page is initially rendered, I was hoping to just package it up and post it back to the server to be transformed into an xlsx without needing to query the database again. That's where I was trying to go with the ajax call. I'm totally okay with having the standard browser dialog pop-up (save as, open, cancel, etc).
Please let me know if anything about my scenario is unclear. It's highly possible I'm going about this in a weird way (I don't normally do web development, so the stateless world of http GETs and POSTs isn't very intuitive for me sometimes).
Hi kylemilnerm,
So I wanted to return to you really to confirm the behavior I believe you are looking for as it relates to this scenario. As I am understanding, you are wanting for the export/download to execute directly without the user needing to perform the extra step of selecting to 'SaveAs or Open" in the dialog. Please confirm.
First, thinking about the 'redirection' aspect that you had mentioned; with this scenario there really isn't a page re-direction occurring. While the user is making the selection from the dialog, the 'main' page remains open. After the selections is made to SaveAs or Open the file, the users focus is returned to the 'main' page.
With regards to making an ajax call, this wouldn't really work primarily because upon receiving the request, it has no idea what to do with the file. This is what you are seeing. You need to have a full post for the page to respond with the export/download.
Let me know if you need any additional assistance.
Thanks!
Thanks Troy, I appreciate the support. I'll look forward to your next post.
Hi kylemilner,
I'm looking into this issue to see what we can recommend to address this for you. I will proceed with my research and will follow-up with you here on this thread.