Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save tonyfast/cdbfed274b8acae60007 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/cdbfed274b8acae60007 to your computer and use it in GitHub Desktop.
Create a very, very simple table using Jquery
<head>
<!-- Latest compiled and minified CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="table.js"></script>
<script>
$(document).ready( $.get('sample.csv', null, CreateTable ) );
</script>
</head>
<body></body>
1 Timothy Hart thart0@blinklist.com China 60.10.60.201
2 Anthony Ferguson aferguson1@rakuten.co.jp Portugal 112.36.67.159
3 Joseph Taylor jtaylor2@zdnet.com Russia 130.69.224.11
4 Ruth Alvarez ralvarez3@intel.com Estonia 54.196.91.253
5 Nancy Fisher nfisher4@weibo.com Indonesia 176.52.197.168
6 Stephen Lane slane5@storify.com Portugal 242.222.195.132
7 Andrew Wheeler awheeler6@illinois.edu Japan 165.210.167.58
8 Christopher White cwhite7@yahoo.com Palestinian Territory 213.28.81.143
9 Thomas Harris tharris8@thetimes.co.uk Canada 198.89.50.16
10 Gerald Rogers grogers9@shareasale.com Russia 199.227.215.254
11 Ashley Peters apetersa@about.me Indonesia 42.57.233.227
12 Joe Scott jscottb@ucla.edu China 194.251.244.59
13 Betty Mcdonald bmcdonaldc@simplemachines.org Haiti 4.187.194.42
14 Louis Little llittled@digg.com Belarus 18.133.105.177
15 Keith Perez kpereze@bizjournals.com Belarus 71.31.119.209
16 Brandon Welch bwelchf@flickr.com Portugal 242.73.117.241
17 Ashley Wheeler awheelerg@narod.ru Poland 237.190.95.30
18 Andrew Harris aharrish@ed.gov Philippines 98.39.104.1
19 Lois Carroll lcarrolli@paginegialle.it Indonesia 188.132.7.147
20 Andrew Cruz acruzj@whitehouse.gov Russia 150.227.86.71
function CreateTable( data ){
// make simple table in jquery
var rows = data.split('\n');
var $table = $('<table class="table table-bordered"></table>').appendTo( 'body' );
$.each( rows, function(i,d){
var $row = $('<tr></tr>').appendTo( $table );
$.each( d.split(',') , function( i, d){
$( $row ).append('<td>'+d+'</td>');
return null;
});//each.d
return null;
}); //each.rows
return null;
}; //CreateTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment