• Stars
    star
    865
  • Rank 52,730 (Top 2 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”ฝ Display any CSV (comma separated values) file as a searchable, filterable, pretty HTML table

CSV to HTML Table

Display any CSV file as a searchable, filterable, pretty HTML table. Done in 100% JavaScript.

Check out the working demo: https://csv-to-html-table.netlify.app/

Screen Shot 2021-03-26 at 4 53 39 PM

Usage

1. Clone this repository (in the command line)

git clone [email protected]:derekeder/csv-to-html-table.git
cd csv-to-html-table

2. Add your CSV file to the data/ folder

3. In index.html set your options in the CsvToHtmlTable.init() function

<script>
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false}
  });
</script>
Available options
  • csv_path Path to your CSV file.
  • element The HTML element to render your table to. Defaults to table-container
  • allow_download if true, shows a link to download the CSV file. Defaults to false
  • csv_options jQuery CSV configuration. Use this if you want to use a custom delimiter or separator in your input file. See their documentation.
  • datatables_options DataTables configuration. See their documentation.
  • custom_formatting New! A list of column indexes and custom functions to format your data (see below)
Custom formatting

If you want to do custom formatting for one or more column, you can pass in an array of arrays containing the index of the column and a custom function for formatting it. You can pass in multiple formatters and they will be executed in order.

The custom functions must take in one parameter (the value in the cell) and return a HTML string:

Example:

<script>

  //my custom function that creates a hyperlink
  function format_link(link){
    if (link)
      return "<a href='" + link + "' target='_blank'>" + link + "</a>";
    else
      return "";
  }

  //initializing the table
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false},
    custom_formatting: [[4, format_link]] //execute the function on the 4th column of every row
  });
</script>

Note that you should take care about HTML escaping to avoid XSS or broken layout. jQuery has a nice function text() which safely escapes HTML from value.

4. Run it

You can run this locally using this handy python command:

python -m SimpleHTTPServer

...or with Python 3:

python -m http.server

navigate to http://localhost:8000/

5. Deploy it

GitHub pages You can host your table on GitHub pages for free! Once you've made all your changes and committed them, push everything in the master branch to gh-pages which automatically enables GitHub pages.

git push origin master:gh-pages

Then navigate to http://your-github-username.github.io/csv-to-html-table/

Read more on working with GitHub pages projects.

Web server This project should work on any web server. Upload this entire project (including all the css, data, fonts and js folders) to a public folder on your server using FTP.

6. iframe it (optional)

Want to embed your nifty table on your website? You can use an iframe. Once you've deployed your table (above in step 5) you can link to it in an iframe right in your HTML.

<iframe style="border-style: none;" src="http://derekeder.github.io/csv-to-html-table/" height="950" width="600"></iframe>

Dependencies

  • Bootstrap 4 - Responsive HTML, CSS and Javascript framework
  • jQuery - a fast, small, and feature-rich JavaScript library
  • jQuery CSV - Parse CSV (Comma Separated Values) to Javascript arrays or dictionaries.
  • DataTables - add advanced interaction controls to any HTML table.

Common issues/troubleshooting

If your table isn't displaying any data, try the following:

  1. Use the Chrome developer console or install Firebug for FireFox. This will allow you to debug your javascript.
  2. Open your table in the browser and open the javascript console
    • Chrome developer console on a Mac: Option+Command+J
    • Chrome developer console on a PC: Control+Shift+J
    • Firebug in Firefox: Tools => Web Developer => Firebug => Open Firebug)
  3. If you do see javascript errors, the error will tell you what line it is failing on. Best to start by going there!

Errors / Bugs

If something is not behaving intuitively, it is a bug, and should be reported. Report it here: https://github.com/derekeder/csv-to-html-table/issues

Contributors

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Send a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2018 Derek Eder. Released under the MIT License.

More Repositories

1

FusionTable-Map-Template

๐ŸŒŽ Searchable Map Template using Google Maps and Fusion Tables
CSS
331
star
2

Fusion-Tables-to-HTML-Table

โš ๏ธ DEPRECATED: Output a Fusion Table in a nice pretty HTML table
PHP
24
star
3

Socrata-to-FusionTables

โš ๏ธ DEPRECATED: PHP script to scrape a Socrata dataset and import it in to a Google Fusion Table
PHP
11
star
4

fusiontips

fusiontips javascript library updated to work with the Fusion Tables v1 API
JavaScript
10
star
5

derekeder.com

๐Ÿ  Personal website for Derek Eder
HTML
5
star
6

FusionTable-Map-Template-Heroku

โš ๏ธ DEPRECATED: Searchable Map Template stuffed in to a Sinatra app with hooks to easily deploy to Heroku
JavaScript
4
star
7

chicago-food-inspections-web

See what restaurants, bars, grocery stores and schools have passed or failed their city food inspections
JavaScript
3
star
8

obscure-address-google-sheets

Google App Script for obscuring addresses to the nearest 100 block
JavaScript
2
star
9

youtube-playlist-images

Fetches vido preview images from all videos in a YouTube playlist
Python
2
star
10

ChicagoClinicsMap

Map of all neighborhood, mental health and WIC clinics in Chicago IL
CSS
2
star
11

chicago-food-inspections-import

import script for chicago-food-inspections-web
PHP
2
star
12

oak-park-budget

Explore the Village of Oak Park's budget from 2013 to 2021 and learn how the money is being spent.
JavaScript
2
star
13

share-the-share

Share my Share is an easy way to donate your CSA share. Tell us when you canโ€™t make it to the market, and we will arrange for a local food pantry to pick up your box.
JavaScript
2
star
14

twine-temp

Rails app for reading and writing temperature readings from a Supermechanical Twine
Ruby
2
star
15

super-pac-man

Ruby
1
star
16

batch-geocode

Script that takes in a CSV of addresses and geocodes them using the Geocoder ruby gem
Ruby
1
star
17

derekeder.com-old

Personal website
CSS
1
star