Skip to content
Browse files

now able to add element cells to the table.

  • Loading branch information...
1 parent dd588d6 commit 4d6f41918b8e2b9dfc97ddfeff73a86e97528e91 @reednj committed
Showing with 33 additions and 6 deletions.
  1. +22 −4 Source/jsTable.js
  2. +11 −2 Test/test.html
View
26 Source/jsTable.js
@@ -101,11 +101,21 @@ var jsTable = new Class({
var element_id = this._getCellElementId(this.data.length, column_name);
// create the cell element
- $e('td', {
+ var new_td = $e('td', {
'id': element_id,
- 'text': cell_content,
'class':'jst-' + column_name
- }).inject(new_row);
+ });
+
+ // insert elements into the table directly.
+ // everything else gets converted to a string and
+ // goes in as innerHTML
+ if($type(cell_content) == 'element') {
+ new_td.grab(cell_content);
+ } else {
+ new_td.innerHTML = cell_content;
+ }
+
+ new_row.grab(new_td);
// add to the internal data
row_data.push(cell_content);
@@ -147,8 +157,16 @@ var jsTable = new Class({
column_id = this._getColumnIndex(column_id);
}
+ var td = $(this._getCellElementId(row_id, column_id));
+
+ if($type(cell_content) == 'element') {
+ td.empty();
+ td.inject(cell_content);
+ } else {
+ td.innerHTML = cell_content;
+ }
+
this.data[row_id][column_id] = cell_content;
- $(this._getCellElementId(row_id, column_id)).innerHTML = cell_content;
},
toData: function(format) {
View
13 Test/test.html
@@ -23,10 +23,19 @@
jst.addColumn('id', 'id');
jst.addColumn('desc', 'Description');
+ jst.addColumn('button', 'delete');
for(i=0; i < 25; i++) {
var id = (Math.random() * 100).round();
- jst.addRow(id, 'description-' + id);
+
+ jst.addRow(
+ id,
+ 'description-' + id,
+ $e('a', {
+ 'text':'x',
+ 'href':'javascript:null'
+ })
+ );
}
$('r1').innerHTML = jst.getCell(1, 'desc');
@@ -35,7 +44,7 @@
jst.setCell(0, 'desc', 'TEST1');
jst.setCell(2, 0, 'TEST2');
- $('t2').innerHTML = jst.toJson();
+ //$('t2').innerHTML = jst.toJson();
},
delete_row: function() {

0 comments on commit 4d6f419

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