Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 2e96e60571661eca1ca661c978662e7726cf2ac3 1 parent 4876c42
Joe Germuska authored October 13, 2012

Showing 1 changed file with 9 additions and 4 deletions. Show diff stats Hide diff stats

  1. 13  src/tabletop.js
13  src/tabletop.js
@@ -43,6 +43,7 @@
43 43
     this.postProcess = options.postProcess;
44 44
     this.debug = !!options.debug;
45 45
     this.query = options.query || '';
  46
+    this.names = options.names;
46 47
 
47 48
     /* Be friendly about what you accept */
48 49
     if(/key=/.test(this.key)) {
@@ -208,6 +209,7 @@
208 209
       var model = new Tabletop.Model( { data: data, 
209 210
                                     parseNumbers: this.parseNumbers,
210 211
                                     postProcess: this.postProcess,
  212
+                                    names: this.names,
211 213
                                     tabletop: this } );
212 214
       this.models[ model.name ] = model;
213 215
       if(this.model_names.indexOf(model.name) == -1) {
@@ -247,6 +249,7 @@
247 249
   Tabletop.Model = function(options) {
248 250
     var i, j, ilen, jlen;
249 251
     this.column_names = [];
  252
+    this.names = options.names || null;
250 253
     this.name = options.data.feed.title.$t;
251 254
     this.elements = [];
252 255
     this.raw = options.data; // A copy of the sheet's raw data, for accessing minutiae
@@ -262,15 +265,17 @@
262 265
         this.column_names.push( key.replace("gsx$","") );
263 266
     }
264 267
 
  268
+    if (!this.names) { this.names = this.column_names; }
  269
+
265 270
     for(i = 0, ilen =  options.data.feed.entry.length ; i < ilen; i++) {
266 271
       var source = options.data.feed.entry[i];
267 272
       var element = {};
268 273
       for(var j = 0, jlen = this.column_names.length; j < jlen ; j++) {
269 274
         var cell = source[ "gsx$" + this.column_names[j] ];
270 275
         if(options.parseNumbers && cell.$t !== '' && !isNaN(cell.$t))
271  
-          element[ this.column_names[j] ] = +cell.$t;
  276
+          element[ this.names[j] ] = +cell.$t;
272 277
         else
273  
-          element[ this.column_names[j] ] = cell.$t;
  278
+          element[ this.names[j] ] = cell.$t;
274 279
       }
275 280
       if(element.rowNumber === undefined)
276 281
         element.rowNumber = i + 1;
@@ -297,8 +302,8 @@
297 302
           i, j, ilen, jlen;
298 303
       for(i = 0, ilen = this.elements.length; i < ilen; i++) {
299 304
         var row = [];
300  
-        for(j = 0, jlen = this.column_names.length; j < jlen ; j++) {
301  
-          row.push( this.elements[i][ this.column_names[j] ] );
  305
+        for(j = 0, jlen = this.names.length; j < jlen ; j++) {
  306
+          row.push( this.elements[i][ this.names[j] ] );
302 307
         }
303 308
         array.push(row);
304 309
       }

0 notes on commit 2e96e60

Please sign in to comment.
Something went wrong with that request. Please try again.