Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery data table that exports to csv?

Posted on 2010-08-13
5
Medium Priority
?
1,939 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 2000 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 2000 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

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

670 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