Solved

jquery data table that exports to csv?

Posted on 2010-08-13
5
1,933 Views
Last Modified: 2012-05-10
Hello,

Anyone know of a good jquery data table plugin that gives you an option to select columns of data to export?  I would like to export an email column that contains email addresses so that I can create a mass email with all my contacts. I'm guessing that a csv export is the best option, but I'm looking for good ideas?
0
Comment
Question by:cgray1223
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33434872
Not a plugin, save the following as cgray1223.php

<?php
    function add_key_value($key,$value){
        $file = "emails.txt";
        $fh = fopen($file, 'a') or die("can't open file");
        $stringData = "$key=$value\r\n";
        fwrite($fh, $stringData);
        fclose($fh);
    }
    
    if(isset($_POST["emails"])) {
        foreach($_POST[emails] as $email) {
            add_key_value($email,$email);
        }
        echo "happy end!";
    }
    else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
    $(document).ready(function() {
        $("th").click(function() {
            var json = {emails:[]};
            var columnNumber = $(this).parent().children().index($(this))
             $(this).parents("table").children("tbody").children("tr").each(function() {
                json.emails[json.emails.length] = $(this).children("td:eq(2)").text();
            });
            $.post("cgray1223.php", json, function(data) { $("#div2update").html(data); });
        });
    });
</script>
</head>
<body>
<table border="2">
<thead>
    <tr><th>First Name</th><th>Last Name</th><th>mail</th></tr>
</thead>
<tbody>
    <tr><td>Bob</td><td>Sponge</td><td>bob.sponge@hotmail.com</td></tr>
    <tr><td>Bob</td><td>Dylan</td><td>bob.dylan@hotmail.com</td></tr>
</tbody>
</table>
<div id="div2update"></div>
</body>
</html>
<?     
    }
?>

Open in new window

0
 

Author Comment

by:cgray1223
ID: 33438496
This is very nice thanks for the help!  Do you have any ideas on how to pull in data like the below and populate the table dynamically?

I have data stored as below in a file mailinglist.properties:
test@gmail1.com=test@gmail.com,first name,last name
test@gmail2.com=test@gmail.com,first name,last name
test@gmail3.com=test@gmail.com,first name,last name
.....
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 33438576
check this :

            $.get("mailinglist.properties",function(data) {
                  $.map(data.split("\n"),function(row) {
                        var item = row.split(",");
                        if(item.length == 3) {
                              $("#tableID").append("" + item[0] + "" + item[1] + "" + item[2] + "");      
                        }
                  });
            })

test page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$.get("mailinglist.properties",function(data) {
			$.map(data.split("\n"),function(row) {
				var item = row.split(",");
				if(item.length == 3) {
					$("#tableID").append("<tr><td>" + item[0] + "</td><td>" + item[1] + "</td><td>" + item[2] + "</td></tr>");	
				}
			});
		})
	});
</script>
</head>
<body>
<table id="tableID" border="1">
</table>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:cgray1223
ID: 33442957
Thanks!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33442959
You're welcome! Thanks for the points!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passport Expiry 3 59
jQuery for Each 12 35
jQuery - retrieve the  href="/user/Jane/" from the previous link 3 18
check a checkbox of a checkboxes group in bootstrap 2 45
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

820 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