Download
User Rating: 1.3/5 ( 1 votes)
CSV Parser is simple CSV Reader in jQuery. This is a skeleton for making datatables from a csv in jQuery. Easy stuff but I thought I'd store it here for others to use.
Source: github.com
1. INCLUDE JS FILE
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
2. HTML
<div id="container"></div>
3. CREATE A CSV FILE
Create a csv file with name is "data.csv" that has content like this
name,phone,nickname,state
bob,503,bobby,oregon
steve,707,stevie,california
4. JAVASCRIPT
$.get('data.csv', function(data) {
// start the table
var html = '<table class="table table-bordered">';
// split into lines
var rows = data.split("\n");
// parse lines
rows.forEach( function getvalues(ourrow) {
// start a table row
html += "<tr>";
// split line into columns
var columns = ourrow.split(",");
html += "<td>" + columns[0] + "</td>";
html += "<td>" + columns[1] + "</td>";
html += "<td>" + columns[2] + "</td>";
// close row
html += "</tr>";
})
// close table
html += "</table>";
// insert into div
$('#container').append(html);
});