Hi, I have an igGrid configured with remote filtering, sorting, paging, and column hiding features. I'm setting up Excel export feature for this grid:
$.ig.GridExcelExporter.exportGrid($("#CompaniesGrid"), { fileName: "CompaniesGrid", gridFeatureOptions: { sorting: "applied", filtering: "filteredRowsOnly", paging: "allRows", hiding: "visibleColumnsOnly", } });
Exporing to Excel works, but it only exports the currently visible page, although I have the paging option set to "allRows", and NOT "currentPage".
Analyzing the web requests using Fiddler shows that when loading a page the grid makes a datasource query with the pageindex and pagesize arguments, and filtering, sorting, etc. set correctly.
But, when clicking the export button, I observe that the grid does not make any additional web requests to the remote datasource. What I'd expect is that the grid should either query the datasource page-by-page until all rows are loaded, or, it may query the whole datasource without paging options set.
Anyway none of them happens, the grid only exports the data that is currently visible in it.
Do you have an idea what could be wrong in this case?
regards,
Peter
wvusaf,
This is a brilliant idea! Save the query string into a session variable when requesting griddatasourceaction, and when the controller gets a request for the export action, it just reads the session variable, and filters the data accordingly. So the fitlering of the excel export will always be the same as the last filtering of the grid.
Thanks, I will certainly give it a try!
Peter,
i get what you're saying. it is alot of data. i see the same thing. i have several thousands of records returned as well.
but, you can pass whatever data you want to when you make the request to export everything, if that's what you want to do.as an example this is what i do:
// 1) start the ajax call $.ajax({ // This is the data source controller action url: '/Reports/ReportExport', method: "GET", dataType: "json", data: { reportType: type }, // 'reportType' tells what type of report this is success: function (data) { $.ig.GridExcelExporter.exportGrid($("#report-grid"), { fileName: filename, dataExportMode: "allRows", gridFeatureOptions: { paging: "allRows", sorting: "applied" } }, { exportStarting: function (sender, args) { // 2) pass the fetched data, which is already sorted, filtered, etc. var gridData = $.parseJSON(data); sender._gridData = gridData; }, }); } });
but, you should know that in my implementation, i actually use a datatable as the datasource for my grid. each time i sort, filter, page, etc... the grid automatically calls a controller action that I specify in advance, and it passes along the query string parameters that you mention that you want to pass. i sort the datatable on the server and then store it in a session variable so that i have it when any subsequent sorting or paging happens. you could do the same thing by passing the data you want to as in the example above where i'm sending "data: { reportType: type }, // 'reportType' tells what type of report this is". that's all i pass, but you could customize this as you want and sort or filter as you need before passing the data back.
The line of code that's the show-stopper is "sender._gridData = gridData;", but it still works. it does export, and even with several thousand rows, i can export mine fairly quickly.
Hi,
I'm statring to get what you guys are telling me, but you should be aware that the filtering, sorting, paging etc. that you see actually happens on the client!
This might not make a difference when dealing with these small examples, but if you have a lot, and I mean, a LOT of data, this start to matter quite much:
So, in the normal grid data request the following happens:
You set sorting, filtering, paging etc. on the grid, and when it updates, it sends a web request, where these options are encoded like this:
MyController/MyAction?sort(MyColumn)=asc&filter(MyOtherColumn)=contains(whatever)page=0&pageSize=10&etc...
So, all processing happens on the server, it filters, sorts, and returns only the 10 requested entities in a JSON.
On the other hand, with the Excel export, the following happens:
The AJAX request that your code sends, does the following:
MyController/MyAction
See? No arguments! It gets everything! So, after all data has been downloaded, you override the datasource in the exportStarting event handler with the newly downloaded datasource, and the exporter applies the filtering, sorting etc. locally, on the client, with really heavy CPU and memory usage, and does the export.
As I said, the big, or even actually HUGE difference comes when you deal with lots of data. I did a quick test, the AJAX request itself took 3 minutes to complete (28 MB of data according to Fiddler), and my browser was processing the data for another 3 minutes, popping up the "Kill page?" dialog tho times while processing. I have a fairly big data table with nearly 30 columns and 6500 rows.
So, the real solution for this would be to send the filtering, sorting, etc. options to the server(the exact same way as the grid does), let the server do the heavy data processing, and return only what is needed. Of course, one might want to download the whole table, e.g. for archiving purposes, in this case, some incremental downloading would be really good (multiple paged data requests until all data downloaded, and then combining it into a single excel file on the client for example)
This is why I asked whether it is possible to get these settings from the grid somehow: sort(MyColumn)=asc&filter(MyOtherColumn)=contains(whatever)page=0&pageSize=10
If I could get them, I could hack it into the AJAX request, and handle processing on the server like I do in case of grid updates. I could even send multiple paged requests, and after all of them finished, combine the result JSONs into to one big JSON and pass that to _gridData in exportStarting event handler? This way I could possibly work around this issue the proper way. I think only thing I need for this is getting the grid setting somehow.
So, could you please help me how to get them?
Hello Peter,
As wvusaf posted, you should be able to export the grid will all features utilizing his method.
Let me know if I can of further assistance.
It actually can export with all the grid options you want.in my javascript, i do something like this:
$.ig.GridExcelExporter.exportGrid($("#report-grid"), { fileName: filename, dataExportMode: "allRows", gridFeatureOptions: { paging: "allRows", sorting: "applied" } }
what that does is preserve all the sorting and paging, and mine even downloads with hidden columns hidden in the excel spreadsheet.
so, give it a try, i think you see the export looking exactly like your grid.