PDA

View Full Version : Problem with Export Grid Data



khushi
24 Nov 2010, 3:45 AM
I want to export Grid data into csv/excel. I am using Code that extracts the data of a GridPanel's Store, and uses the ColumnModel to construct an XML Excel document, converts it to Base64, and loads it into a data URL in a link.But it is not working Properly.

Is there is another way to export grid data in Sencha ?

Please help me.

Thanx in advance

Condor
24 Nov 2010, 4:18 AM
Data URLs don't work on all browsers.

Javascript has no other way to generate documents, so the only option left is to create the Excel document on the server.

khushi
24 Nov 2010, 4:32 AM
Thanks for the reply....

i am not able to create the Excel document on the server and attach it to grid ? can you send an sample code for that.

Condor
24 Nov 2010, 9:10 AM
No, you normally do another request to the server to request the Excel document (Animal's LinkButton is very suited for that).

khushi
27 Nov 2010, 2:05 AM
Thanks Condor,

Animal's LinkButton is helpful for me. but i am not able to change name of exported excel sheet it takes an random number with extension .xls.part ( like 5nbLs6Xz.xls.part).

Please help me.

Thanx in advance

Condor
27 Nov 2010, 2:29 AM
Your server needs to set the response header:

Content-disposition: attachment; filename="myfile.xls"

khushi
27 Nov 2010, 2:44 AM
i have set response header using following code :

<?php
header('Content-disposition: attachment; filename="myfile.xls"');
?>

but it's not working. where should i add this code ?

Condor
27 Nov 2010, 3:10 AM
Where did you add this? It needs to be in the response header of the returned XLS file.

khushi
27 Nov 2010, 4:01 AM
I am adding this code to the head section of page. now i am adding this code in grid panel :

bbar: new Ext.PagingToolbar({
store: store,
pageSize: 20,
plugins: [filters],
buttons: [{
id: 'grid-excel-button',
text: 'Excel',
handler: function(){
document.location='data:application/vnd.ms-excel;Content-Disposition: attachment;filename=MySpreadsheet.xls;,base64,' +Base64.encode(grid.getExcelXml());
}
}]
})


but it's not working. where should i get response header of the returned XLS file ?can you please tell me where should i add ?

Condor
27 Nov 2010, 6:06 AM
No, that only works for server-generated xml documents, not for data urls.

Unfortunately, the data url specifications don't have way to set the filename.