Solved

jquery data table that exports to csv?

Posted on 2010-08-13
5
1,938 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
[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
  • 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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)

617 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