Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Commit

Permalink
bugfix: tojson now works correctly with element cells
Browse files Browse the repository at this point in the history
  • Loading branch information
reednj committed Aug 22, 2011
1 parent dc927f9 commit d824bde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions Source/jsTable.js
Expand Up @@ -183,15 +183,25 @@ var jsTable = new Class({
// dump every column of the table to an object. // dump every column of the table to an object.
return this.toData(this.column_list.map(function(o) { return o.name; })); return this.toData(this.column_list.map(function(o) { return o.name; }));
} else if($type(format) == 'string') { } else if($type(format) == 'string') {

// assume the string is a column name, return just that column // assume the string is a column name, return just that column
var column_id = this._getColumnIndex(format); var column_id = this._getColumnIndex(format);
return this.data.map(function(row) { return row[column_id]; }); return this.data.map(function(row) {
if($type(row[column_id]) != 'element') {
return row[column_id];
} else {
return null;
}
});

} else if($type(format) == 'array') { } else if($type(format) == 'array') {
return this.data.map(function(row) { return this.data.map(function(row) {
var new_row = {}; var new_row = {};


for(var i=0; i < row.length; i++) { for(var i=0; i < row.length; i++) {
new_row[this.column_list[i].name] = row[i]; if($type(row[i]) != 'element') {
new_row[this.column_list[i].name] = row[i];
}
} }


return new_row; return new_row;
Expand Down
4 changes: 2 additions & 2 deletions Test/test.html
Expand Up @@ -29,7 +29,7 @@
jst.addColumn('desc', 'Description'); jst.addColumn('desc', 'Description');
jst.addColumn('button', 'delete'); jst.addColumn('button', 'delete');


for(i=0; i < 25; i++) { for(i=0; i < 10; i++) {
var id = (Math.random() * 100).round(); var id = (Math.random() * 100).round();


jst.addRow( jst.addRow(
Expand All @@ -48,7 +48,7 @@
jst.setCell(0, 'desc', 'TEST1'); jst.setCell(0, 'desc', 'TEST1');
jst.setCell(2, 0, 'TEST2'); jst.setCell(2, 0, 'TEST2');


//$('t2').innerHTML = jst.toJson(); $('t2').innerHTML = jst.toJson();
}, },


delete_row: function() { delete_row: function() {
Expand Down

0 comments on commit d824bde

Please sign in to comment.