Solved

Download to CSV file jquery

Posted on 2014-01-29
3
756 Views
Last Modified: 2014-02-04
Hello,
  I have data in an HTML table. I would like to read the data in the table and download it in a CSV format .

Basically, the table has a check box. name and address and download button. When the download button is press I would like to read the data in the selected row and force an http download of the file.  

Thanks for your help
0
Comment
Question by:SiemensSEN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39817778
You can't do this with javascript - you would need to use a server-side script, such as PHP.

When the download button is pressed, you would need to send your data, using Javascript / AJAX to a script on the server. That script would create the file, and then send back any info (filename /path etc.) back into Javascript, where you could then handle it however you like
0
 

Author Comment

by:SiemensSEN
ID: 39817791
Ok,

So, the procedure is:

JavaScript
-- Loop thru the table
-- construct a CSV string
-- use ajax and pass the CSV string to the server script

Server
-- Create a file with CSVString content
-- then force the HTTP download.

Thanks
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39817836
Yeah, pretty much, although you say you only want to send the selected row, so there should be no need to loop through the table.

You'll probably also find it easier to build the CSV string on the server-side. I know PHP has some useful CSV functions, such as fputcsv() - it takes a file pointer and an array, converts the array into a CSV string and writes it to a file - easy :)

In that case you'd just pass your individual values to the server using one of the jQuery ajax functions - ajax(), post() etc.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question