Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakewhiteley/getgoogledoc
Lightweight and simple jQuery plugin for fetching a Google Drive spreadsheet via ajax (400b min + gzipped)
https://github.com/jakewhiteley/getgoogledoc
Last synced: 10 days ago
JSON representation
Lightweight and simple jQuery plugin for fetching a Google Drive spreadsheet via ajax (400b min + gzipped)
- Host: GitHub
- URL: https://github.com/jakewhiteley/getgoogledoc
- Owner: jakewhiteley
- License: mit
- Created: 2014-10-23T21:36:40.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-21T16:25:19.000Z (about 10 years ago)
- Last Synced: 2024-12-06T21:43:23.318Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 192 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
getGoogleDoc
============`$.getGoogleDoc` will fetch the data from a public spreadsheet hosted on Google Drive, and return it as an array of objects, with each object representing a row of your spreadsheet. It comes in at 400b when gzipped and works across all major browsers - allowing anyone to easily edit data for a project.
## Using getGoogleDoc
### Basic Implementation
This plugin follows the spec for similar AJAX shorthand methods like `$.getJSON`, so you can use the plugin by passing it the public key of your sheet, and a success function to handle the response.```JavaScript
// fetch spreadsheet with a success function
$.getGoogleDoc('1l-5ToWOOlmaPhlzdKsLggZKfenSMNZTkzXzFMg9P1es', function (data) {
// log a table of results to the console
console.table(data)
})
```
### Using jQuery promiseAlternatively, you can make use of the jQuery promise interface methods such as `.done()` and .`fail()` if you want more control.
```JavaScript
// fetch spreadsheet as a promise
$.getGoogleDoc('1l-5ToWOOlmaPhlzdKsLggZKfenSMNZTkzXzFMg9P1es')
.done(function (data) {
console.table(data)
})
.fail(function (data) {
console.log('getGoogleDoc failed')
})
.always(function (data) {
console.log('getGoogleDoc complete')
});
```
### Example Data ReturnedThe callback function is called with the parsed contents of the Google spreadsheet as a parameter. This is an Array of Objects with an Object for each row in the spreadsheet. Each objects keys are the column names from your table, and the values are the contents of the relevant cell.
```JavaScript
[
{
name: 'James',
surname: 'Brimble',
age: 27,
address: null
}, {
name: 'Alice',
surname: 'Brimble',
age: 26,
address: null
} //, { ... }
]
```