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" and sharing the sheet with the public. You must do both or the table will not work! To publish the sheet, go to the File menu and selected Publish to the web. To 'share' the sheet with the public, hit the share menu and select 'Anyone on the internet can find and view'

Then grab the url of the spreadsheet or the "key" from the URL. That's the long string of numbers in the middle of URL. Either one is fine.

Start Coding

Open js/graphic.js and put the key you just copied in the very first variable in the third line of the code:

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!

Customize

In my example, I've wrapped the table in some sensible HTML and CSS. so you'll want to edit index.html to add a title, intro graf, source and credit.

Some extra DataTable options are included in comments.

	//Initialize the DataTable object and put settings in
	$("#mySelection").DataTable({
		...
			//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 than add more. "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>');  

Serve it up!

If you've previously viewed web projects by double-clicking on an index.html file and opening that in a browser, that won't work here. To view the project, we'll have to start a development server. But don't worry, once you upload the project to the web somewhere, you won't have to start a server or anything. You'll go to the website and it will just work.

To start a dev server, first navigate to your project folder with the terminal (these instructions for Linux/OS X):

cd /path/to/project

Make sure this is the folder which contains index.html. Then run:

python -m SimpleHTTPServer

The terminal will return: Serving HTTP on 0.0.0.0 port 8000 .... That means you can type in 0.0.0.0:8000 in your browser. You should see your project.

tabletop-to-datatables's People

Contributors

scottpham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tabletop-to-datatables's Issues

Upgrading to papaparse.js

Hi Scott, thanks for making this super helpful tool. I've found that it works great for my project needs. Unfortunately, it looks like tabletop is being depreciated by Google (https://github.com/jsoma/tabletop). While your script works just fine now, it looks like it may no longer work by mid-2021. I wonder if you plan on upgrading it to use papaparse instead of tabletop? Converting over looks simple enough and I tried making some the changes myself, but unfortunately I think I may have broken the script instead, and I can't get it to work with the papaparse backend.

Many thanks again for making this project available!

Sheets not connecting.

Looks good,
Followed the instruction.
Tried it first on my server using the demo material and code.
Works great. :)

Changed the key, and column settings to match my sheet and I get 'nothing' where the data should be.

What am I doing wrong or missing?

GSheet:

Site URL:

===Snip from graphic.js file:===

var key = "1y4WU_hNpSeYDVuWaHve7TVRhDePvKl39Ue21z9GskeA"; //My Key

//"data" refers to the column name with no spaces and no capitals
//punctuation or numbers in your column name
//"title" is the column name you want to appear in the published table
var columns = [
{ "data": "acountry", "title": "Country","defaultContent": ""},
{ "data": "drug", "title": "Drug Name","defaultContent": ""},
{ "data": "active", "title": "Active Ingredient","defaultContent": ""},
{ "data": "company", "title": "Company" },
{ "data": "violations", "title": "Claims" },
{ "data": "total-award", "title": "Total Awarded" }];

I left the columns in from the demo sheet just to test . By replacing my key with the demo key I was able to figure our that the issue does not seem to be with column data, added the default content to dismiss the error for null content. But something with the key is possibly in error? I did share to all the world to view with the link.

Any help would be great.

Which file contains the path to the Google Sheet?

Hi, I could use a little help.

I inadvertently moved my clients public Google Sheet that I was pulling into his SquareSpace site. Since I did that, the sheet now has a new URL that I need to call. It has been over a year since I worked with Tabletop To Datatables code. Could someone save me alot of time and headache and remind me in which file do I place the path to my sheet please?

Table not showing up

I shared my table AND published it. I copied the key from the share button. It is set up so that anyone can find and view it.

Here is the code I edited:

`
//enter google sheets key here
var key =
"1bs-gARbVBwuopFStBzTypVOBCPpe-6qhAFj1uNdSevk";

//"data" refers to the column name with no spaces and no capitals
//punctuation or numbers in your column name
//"title" is the column name you want to appear in the published table
var columns = [
{ "
data": "shootid",
"title": "ShootID"
}, {
"data": "title",
"title": "Title"
}, {
"data": "description",
"title": "Description"
}, {
"data": "duration",
"title": "Duration"
}
}, {
"data": "names",
"title": "Names"
}
}, {
"data": "tags",
"title": "Tags"
}
}, {
"data": "Cover",
"title": "cover"
}
}, {
"data": "downloadurl",
"title": "Video"
}
}, {
"data": "program",
"title": "Program"
}
}, {
"data": "network",
"title": "Network"
}
}, {
"data": "website",
"title": "Website"
}
}, {
"data": "category",
"title": "Category"
}
}, {
"data": "dateadded",
"title": "Date Added"
}];
`

I tried putting every share link possible in the "var key" but nothing works. All of the columns on my spreadsheet are named exactly the same as what appears in "date":, all lower-key.

I'm not sure where I'm going wrong?

Adding file export buttons

Hi,

I'm a journalist (not a dev), and I would like to ask you if it's currently possible to add file export buttons to tabletop-to-datatables as shown in the datatables documentation. I tried to initilize the options on my js file (after importing the required librairies to the html file), but couldn't make it work.

Could you please give me a hand?

Thanks a lot,

Camilo

My table has disappeared from my site

Hello,
I have used your code on a SquareSpace website. I uploaded graphic.js and tabletop.js directly to the site but all other scripts and css styles are being called. Did any of those files move? What could be the reason that my table disappeared?

Responsiveness

Hey Scott,

I'm having trouble making this table responsive. Do you have a tip for that? Thanks!

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.