JSONP Google Spreadsheet with DataCollection.js
by Josh Weir
HTML
<script src="https://www.javascriptoo.com/application/html/js/thestorefront/DataCollection.js/data_collection-1.1.5-min.js"></script>
<form id="foo" ajax="true">
<p><label for="name">Name:</label>
<input id="name" name="name" type="text" value=""/></p>
<p><label for="comment">Comment:</label><br/>
<textarea id="comment" name="comment" cols="40"></textarea></p>
<p id="result"></p>
<input type="submit" value="Send"/>
</form>
<div id="results"></div>
JavaScript
//below is an existing public example of retrieving google spreadsheet data using
//ajax call.
//i then published my google spreadsheet (go to spreadsheet and select File > Publish to web and then it gave me url, just get the spreadsheet id and enter it in the obvious section where the id is below.
var url = 'https://spreadsheets.google.com/feeds/cells/1_h2owPRP_P0z4A8B9kHL-UKtcV2KrKyahOnVxhtgYMc/od6/public/values?alt=json-in-script&callback=?';
$.getJSON(url, cellEntries);
var onSuccess = function (data) {
var html = "";
var entries = data.feed.entry;
for (var i = 0, len = entries.length; i < len; ++i) {
html += entries[i].content.$t + ' ';
if ((i + 1) % 3 == 0) {
html += '<br/>';
}
}
$('#results').html(html);
}
function cellEntries(json) {
var dc = new DataCollection(json);
/*
console.log(JSON.stringify(json));
console.log(json);
console.log(dc);
*/
//get the json.version = 1.0
/*
console.log(JSON.stringify(dc.query().filter({version: '1.0'})
.values()));
*/
//get the json.feed.xmlns = http://www.w3.org/2005/Atom
/*
console.log(JSON.stringify(dc.query().filter({feed__xmlns__contains: 'www.w3.org/2005/Atom'})
.values()));
*/
//get the json.feed.entry.gs$cell.row = 1
/*
console.log(JSON.stringify(
dc.query()
.filter({feed__title__$t__is: 'Sheet1'})
.values()));
*/
var dce = new DataCollection(json.feed.entry);
//console.log(JSON.stringify(json.feed.entry));
/*
console.log(JSON.stringify(
dce.query()
.filter({gs$cell__row__is: '1'})
.values()));
console.log(dce.query()
.filter({gs$cell__row__is: '1'})
.values().length);
*/
aryGoogFeed = googFeedToArray(json.feed.entry);
console.log(aryGoogFeed);
var table = document.createElement('table');
table.setAttribute('id',...