View Full Version : export store records to excel

4 May 2012, 10:06 AM
Hi, i need some advice on how to do this or where to look in the documentation.
In general is export Ext store records to excel, using a server side code to generate the excel and retrieve that file, as a link or as http response using excel headers.

Im using Ext.Direct as proxy for all my stores/models.

using store.load() the http request send some parameters as JSON to the server (like page, limit, filter, sorts, etc)
in some point i want to export this store, to excel.

In the server side i have a code that receives all params as a normal store.load() but instead of returning the JSON records, generates an excel.

My problem is how to call this excel method and pass all the params store.load() sends.

Cant do it using with something like store.load({params:{export: true}}) even when the server will understand that he needs to export to excel instead of generating json, store.load() expects a json response, not an excel.

I need something like
- get all the params store.load() will send to the server to load those record.
- send a request using another mechanism like a form ? dunno im lost here. something that sends those params as JSON but doesnt expect a JSON as http response.

anyone can help me on this ? or some similar solution to export to excel
Note that all my store/models load records correctly and i excecute manually that server side excel generator, works properly, just need a way to call him from ext and pass him the params store.load used to load his records.

(sorry for my bad english)

4 May 2012, 10:51 AM
I have used this on server side:

I see there is the following for client side:


4 May 2012, 11:00 AM
thanks for your answer.
im using http://phpexcel.codeplex.com/
the problem is not how to generate excels in server side,
is how to send http request that is send by store.load without using store.load since it expects a json response.

i need all those params store.load used to load its records, to tell the server side export to execute the same query and put those records on a excel.

4 May 2012, 2:45 PM
I usually send an ajax request with parameters to create the XLS

method: 'POST',
url: 'export_table',
params: {
report_params: report_params,
success: function(xhr) {
// clear mask and display
window.open('xls/' + employee_report_name + '.xls');
failure: function() {
// clear mask
alert('AJAX ERROR: Unable to export report, please contact support');


4 May 2012, 3:27 PM
thanks alot.
missing one thing, the report_params.
for me, as im trying to export records from store, i need to get what store.load sends as http request (the JSON) those are my report_params in your code.
its possible to get the json request that a store.load sends to the server ? to pass those same params as report_params ?
thats my problem.

5 May 2012, 5:54 AM
Are you sure? .. the entire benefit of using a server based report is not waiting on the transfer of data over the pipe to get the report.

You would use the same parameters that were used to populate the grid data in the first place and specify that information as a param to the php reports to generate SQL for the report.

You want to send all of the data back from the grid to the report? You can use Ext.Encode() to send your data back if you must.


5 May 2012, 8:10 AM
no i dont want to send the records, i want to send the params that store.load used to load those records,
is not just my own params, it also sends page, limit, sorters, filters, etc, all that makes the JSON request to retrieve those records.
i need to give all those params to my export method so he can reproduce the query, get the records (all this on server side) and produce the excel.

anyway already doing this with something like, havent tested

getLoadParams : function(store)
{ var options = {};

options.filters = store.filters.items;
options.sorters = store.getSorters();
options.groupers = store.groupers.items;
options.page = store.currentPage;
options.start = (store.currentPage - 1) * store.pageSize;
options.limit = store.pageSize;

return options;

missing the method and the action of the proxy api (im using ExtDirect) havent figure how to get those params, then ill have all the params that store.load used to get its records.

then i can pass this options as report_params in your example.
my english fails ;)

btw your code been really usefull for this, kind of using the same no copyrights :D