0

I have been looking for this particular scenario now a while. I know, if the file is on server side, then we can directly fetch and open to for the user directly (without asking the user to save it on some location).

Reference

Well I am using Datatable in my application with sExtends of Tabletools to get the below tools.

enter image description here /Example initialisation/

$(document).ready( function () {
$('#example').dataTable( {
    "dom": 'T<"clear">lfrtip',
    "tableTools": {
        "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
  }
});
});

enter image description here

Now when I click on CSV or Excel button as seen in the second image, it firsts throws a dialog box prompting me to save it, then I will be able to view the content in the sheet. Now what I want is -> Click on the Button Excel or CSV and boom, the excel is open to view directly. Later if the user wants then he can save it manually. Is it possible?

Abb
  • 3,051
  • 3
  • 17
  • 34
  • What is your server-side technology (i.e. Java/JEE, C#/.NET, PHP, etc.)? Do you have access to the server side code? – StvnBrkdll Nov 27 '16 at 15:53
  • The answer to your question is "yes", it is possible, and not too difficult. Briefly: clicking on the "CSV" button should run javascript that calls `window.open()` on a service URL in your web application. The service in your web application should return the data in the response body, in csv format. The response should include a "Content-type" header set to "application/csv". – StvnBrkdll Nov 27 '16 at 15:56
  • @mangotang : using java/J2ee – Abb Nov 27 '16 at 16:23
  • @mangotang : any reference to code available? I want to overwrite the overall existing functionality of the CSV button across application. is it possible too? – Abb Nov 27 '16 at 16:27
  • There are several posts on SO that provide partial answers to your question. They include code samples. http://stackoverflow.com/questions/1999607/download-and-open-pdf-file-using-ajax Try doing a Google search for `"stackoverflow return csv http java -buffer"` – StvnBrkdll Nov 27 '16 at 16:34
  • What does your "backend API" look like? You say it is written in Java. Is it a RESTful service, a servlet, something else? Can you provide information on the API (what are the required request parameters or query string? What does the URL look like?) – StvnBrkdll Nov 27 '16 at 16:38
  • @mangotang : but its on server side, i want it to be purely client side, I dnt want again the client to make a request and fetch as header then open on client side. i already do have data on client side in data tables, want to export that to excel without prompting user a save dialog box option. – Abb Nov 27 '16 at 16:41
  • @mangotang We are using rest api. already we do query oracle database and fetch results depending upon users input on UI, that JSON reponse is shown in Tabular format using Datatables. SOi want to use the existing DataTable grid which is populated already on UI – Abb Nov 27 '16 at 16:43

0 Answers0