PDA

View Full Version : Export to Excel from server side



duskandawn
13 Aug 2010, 3:02 PM
Hello All,
I am trying to get the Export to Excel functionality work from the server side.
I already have the servlet which writes the response data, with the correct header for excel.
But when i make an Ajax request with my grid data on to this servlet, i do not see the save dialogue poping up.

I tried using the isUpload:true, option in my request but still no luck.


function buildRPC2(request){
var extRequest = {
url : '../TestRequest',
method: 'POST',
isUpload : true
};
return extRequest;
}

exportTOExcel: function (){
var grid = Ext.getCmp('gridRegion');
var updatedNewRecs = [];
grid.getStore().each(function(rec){
updatedNewRecs.push(rec.data);
});
Ext.Ajax.request(buildRPC2(({
data : updatedNewRecs

})));
},


I am setting correct headers required for the excel. But no luck.
I read somewhat about the hidden iframe trick, but cannot visualize fully in terms with ExtJS and how to set it up

If that is the only solution, can someone please shed some more light on that technique.

Thank you,

ashaihullin
13 Aug 2010, 7:47 PM
add this to body:


<iframe type="hidden" src="" style="display:none;" id="downloadFrame"></iframe>


then:


var nav = document.getElementById("downloadFrame");
nav.src = 'http://bla.com/TestRequest?params';

Animal
14 Aug 2010, 12:00 AM
Does Ext.Ajax.request have a data option?

When you examine that request in Firebug, what gets sent to the server?

duskandawn
14 Aug 2010, 6:22 AM
I missed posting full code for my builRPC method.
Looks like :


function buildRPC2(request){
var extRequest = {
url : '../TestRequest',
method: 'POST',
isUpload : true
};
if (request.data){
extRequest.jsonData = Ext.encode(request.data);
}
return extRequest;
}

I do see data being sent on to server.
But cant find a way to get the save dialog for excel.
Even with iframe approach how do i pass the whole grid data to the server, Passing data in the request query may be limited.

Please advise,

Animal
14 Aug 2010, 7:10 AM
You cannot download with Ajax. You must submit a form. You must have a hidden form element, and submit that using the Ext.Ajax.request form option.

The server must set the Content-Disposition header.

To be doing this kind of work you MUST be familiar with the HTTP protocol.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1

duskandawn
16 Aug 2010, 10:38 AM
Works perfect now, thanks so much