Press "Enter" to skip to content

A jQuery Parsing And Displaying CSV Files Plugin | jquery-csv

jQuery-CSV is an artifact of a simpler time when the JS Library ecosystem was still very much underdeveloped. This was the first and still is one of the fastest, most compact CSV distributors available.

This is a complete, customizable, battle-tested, and performance-optimized CSV analyzer that follows the traditional jQuery syntax. It features the Chomsky – Type III Slim App. Full (meaning 100%) compliance with IETF RFC 4180. Including covering some edge cases that the specification fails to cover.

how to read a csv file in javascript with example, javascript read local csv file, javascript to read and display contents of csv file in html format, read csv file in javascript line by line

Features:

  • Convert a CSV string to an array
  • Convert a multi-line CSV string to a 2D array
  • Convert a multi-line CSV string to an array of objects (such as header: value pairs)
  • Convert a set of values ​​to a CSV (under development)
  • Convert a group of objects to a CSV (under development)
  • Hooks / Calls to extend the default analysis process
  • The customizable delimiter (default: “) and separator (default:,) characters
  • Node.js support (i.e. CommonJS import and asynchronous callback support)

How to make use of it:

Installation:

# NPM
$ npm install jquery-csv --save

1. Insert the primary JavaScript file csv.js after jQuery JavaScript library.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" 
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" 
        crossorigin="anonymous">
</script>
<script src="src/jquery.csv.js"></script>

2. The JavaScript parses a single line of CSV data into an array of values.

$.csv.toArray(csv)

3. The JavaScript to parse CSV information right into a JavaScript 2D (two-dimensional) array.

$.csv.toArrays(csv)

4. The JavaScript to parse CSV information into an array of objects.

$.csv.toObjects(csv)

5. Possible plugin choices.

$.csv.functionName(csv, {

  // separator
  separator:',',

  // delimiter
  delimiter:'"',

  // shows headers
  headers:true

});

6. Event handlers.

$.csv.functionName(csv, {

  onPreParse: function(){},

  onParseEntry: function(){},

  onParseValue: function(){},

  onPostParse: function(){},

});

7. Use the plugin in node.js.

var fs = require('fs');
var $ = jQuery = require('jQuery');
require('src/jquery.csv.js');

var sample = 'sample.csv';
fs.readFile(sample, 'UTF-8', function(err, csv) {
  $.csv.toArrays(csv, {}, function(err, data) {
    for(var i=0, len=data.length; i<len; i++) {
      console.log(data[i]);
    }
  });
});
Name Description
csvrequiredThe csv data to be transformed.
optionsoptionalAn object containing user-defined overrides for the default options.
callbackoptionalUsed for Node.js-style async callbacks. Uses the form function(err, data).

Parsing And Displaying CSV Files, jQuery-csv Plugin/Github, display csv file in html table javascript, how to write data into csv file in javascript


See Demo And Download

Official Website(evanplaice): Click Here

This superior jQuery/javascript plugin is developed by evanplaice. For extra Advanced Usages, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published.