Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support a 'names' option to override the column headers in the gsheet

  • Loading branch information...
commit 2e96e60571661eca1ca661c978662e7726cf2ac3 1 parent 4876c42
@JoeGermuska authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/tabletop.js
View
13 src/tabletop.js
@@ -43,6 +43,7 @@
this.postProcess = options.postProcess;
this.debug = !!options.debug;
this.query = options.query || '';
+ this.names = options.names;
/* Be friendly about what you accept */
if(/key=/.test(this.key)) {
@@ -208,6 +209,7 @@
var model = new Tabletop.Model( { data: data,
parseNumbers: this.parseNumbers,
postProcess: this.postProcess,
+ names: this.names,
tabletop: this } );
this.models[ model.name ] = model;
if(this.model_names.indexOf(model.name) == -1) {
@@ -247,6 +249,7 @@
Tabletop.Model = function(options) {
var i, j, ilen, jlen;
this.column_names = [];
+ this.names = options.names || null;
this.name = options.data.feed.title.$t;
this.elements = [];
this.raw = options.data; // A copy of the sheet's raw data, for accessing minutiae
@@ -262,15 +265,17 @@
this.column_names.push( key.replace("gsx$","") );
}
+ if (!this.names) { this.names = this.column_names; }
+
for(i = 0, ilen = options.data.feed.entry.length ; i < ilen; i++) {
var source = options.data.feed.entry[i];
var element = {};
for(var j = 0, jlen = this.column_names.length; j < jlen ; j++) {
var cell = source[ "gsx$" + this.column_names[j] ];
if(options.parseNumbers && cell.$t !== '' && !isNaN(cell.$t))
- element[ this.column_names[j] ] = +cell.$t;
+ element[ this.names[j] ] = +cell.$t;
else
- element[ this.column_names[j] ] = cell.$t;
+ element[ this.names[j] ] = cell.$t;
}
if(element.rowNumber === undefined)
element.rowNumber = i + 1;
@@ -297,8 +302,8 @@
i, j, ilen, jlen;
for(i = 0, ilen = this.elements.length; i < ilen; i++) {
var row = [];
- for(j = 0, jlen = this.column_names.length; j < jlen ; j++) {
- row.push( this.elements[i][ this.column_names[j] ] );
+ for(j = 0, jlen = this.names.length; j < jlen ; j++) {
+ row.push( this.elements[i][ this.names[j] ] );
}
array.push(row);
}
Please sign in to comment.
Something went wrong with that request. Please try again.