Giter VIP home page Giter VIP logo

tabletop-to-datatables's Introduction

##Create a Searchable Table With a Google Spreadsheet

This repo creates bootstrap-styled searchable, sortable, responsive tables using the very cool Tabletop.js and the datatables jquery plugin.

It's an update of Chris Essig and Chris Keller's super useful datafeed to datatables repo. Keller's template still works great, but this version uses the latest version of DataTables and removes a lot of deprecated code. The bootstrap implementation is also a little simpler and easier to read here.

Click for a live demo

##Setup

  • First get your data in a google sheet. I like to shorten the column headers to one word each for simplicity, but it's not strictly necessary.

    You'll need to make the sheet fully public by "publishing" (file > publish to the web) and sharing the sheet with the public.

var key = "1jqcH2h3ka0Mzrcp75xHvlt4d2onds0GMqJzsRvgwcyI";
  • Next you'll want to edit the second variable, columns. This variable contains two key/value pairs for each column in your google sheet. The default has an arbitrary three columns with three arbitrary names.
var columns = [ 
    { "data": "manufacturer", "title": "Company" },
    { "data": "incentivesreceived", "title": "Incentives Received" },
    { "data": "total", "title": "Share of Total" }];

Add or delete lines to match the number of columns in your google sheet. The "data" value is the name of your column in your google sheet. Tabletop will strip out spaces and uppercase letters, so if your sheets column is "State Governors" you would write "stategovernors" in for "data". If your google sheet has column names that begin with numbers or contain punctuation, datatables will throw an error.

The `"title"` value should be a string formatted how you'd like it to appear in the published datatable. If you had to remove important punctuation in the google sheet you can put it back here.
  • And that's enough to publish a datatable! I've wrapped the DataTable in some HTML with sensible CSS, so you'll want to edit index.html to add a title, intro graf, source and credit.

##Further Customization

  • Some extra DataTable options are included in comments.
 $("#mySelection").DataTable({  
            "data": data,
            "columns": columns,  
            "order":[[0, "asc"]], //order on 1st column  
            "pagingType": "simple" //no page numbers  
			//uncomment these options to simplify your table  
			//"paging": false,
			//"searching": false,
			//"info": false
			
			});
        }

The defaults are pretty fully featured, so you're more likely to want to remove options. "paging": false removes the paging buttons. "searching": false removes the search box and "info": false removes the "Showing X of Y Entries" text at the bottom of the table. More options are available from the DataTables API.

       $('#graphic').html('<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed table-bordered table-striped table-hover" id="mySelection"></table>');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.