Dojo DataGrid export to excel
-
26-06-2021 - |
Question
I have used exporter plugin the datagrid and have got the grid data in CSV format. But I want to make this data to be downloadable in excel format. One solution is that I can send an ajax request to server and send back the excel.
Just wanted to know if there is a way by which this excel can be created and downloaded without hitting server.
My export code as of now is:
function exportAll(){
dijit.byId("grid").exportGrid("csv", function(str){
alert('Data to be exported',str);
});
};
Solution
See
Exporting a dojo datagrid to a csv file
You cannot open excel via javascript so it needs to be a GET download request.
Send the str
to server with xhrPost
, put into temp-file there, print the temp-url and in the xhrPost
success callback function, call window.open("./" + responseText, "_new");
. Its also possible to use the io.iframe
transport one of the answers in that post shows.
function exportAll(){
dijit.byId("grid").exportGrid("csv", function(str){
dojo.xhrPost({
url: '/putExportData.php',
load: function(tempUrl) {
window.open(tempUrl, "_new");
}
});
});
};