Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return 'this' from all methods that don't return anything else, so th…

…at the methods can be chained together. Fixes #3
  • Loading branch information...
commit 916fdaa8de0a6d908b84983e4b6d7fc7b6cd3bff 1 parent 9a0d49d
@reednj authored
Showing with 24 additions and 7 deletions.
  1. +17 −2 Source/jsTable.js
  2. +7 −5 Test/test.html
View
19 Source/jsTable.js
@@ -127,6 +127,8 @@ var jsTable = new Class({
clear: function() {
this.data = [];
this.tbody.empty();
+
+ return this;
},
setEmptyMessage: function(empty_message, show_header) {
@@ -141,12 +143,16 @@ var jsTable = new Class({
if(!$defined(this.empty_tr)) {
this._createEmptyMessage();
}
+
+ return this;
},
addColumns: function(columns) {
columns.each(function(col) {
this.addColumn(col.name, col.description);
}.bind(this));
+
+ return this;
},
addColumn: function(name, desc) {
@@ -157,6 +163,8 @@ var jsTable = new Class({
// now create the header element
$e('th', {'text': desc, 'class':'jst-'+name}).inject(this.thead.getElement('tr'));
+
+ return this;
},
addRow: function() {
@@ -197,6 +205,8 @@ var jsTable = new Class({
this.options.onRowAdded(this.data.length-1, row_data);
this._setEmptyMessageVisibility();
+
+ return this;
},
deleteRow: function(row_index) {
@@ -215,19 +225,22 @@ var jsTable = new Class({
this.options.onRowDeleted(row_index, row_id);
this._setEmptyMessageVisibility();
+
+ return this;
},
deleteRowById: function(row_id) {
this.deleteRow(this.row_list.indexOf(row_id));
+ return this;
},
// aliases for deleteRow. I find remove move natural than delete for some reason.
removeRow: function(row_index) {
- this.deleteRow(row_index);
+ return this.deleteRow(row_index);
},
removeRowById: function(row_id) {
- this.deleteRowById(row_id);
+ return this.deleteRowById(row_id);
},
getCell: function(row_id, column_id) {
@@ -257,6 +270,8 @@ var jsTable = new Class({
this.data[row_id][column_id] = cell_content;
this.options.onCellUpdated(row_id, column_id, cell_content);
+
+ return this;
},
toData: function(format) {
View
12 Test/test.html
@@ -52,9 +52,7 @@
var jst = this.jst;
- jst.addColumn('id', 'id');
- jst.addColumn('desc', 'Description');
- jst.addColumn('button', 'delete');
+ jst.addColumn('id', 'id').addColumn('desc', 'Description').addColumn('button', 'delete').setEmptyMessage('test', true);
//jst.setEmptyMessage('empty table', true);
@@ -74,8 +72,7 @@
$('r1').innerHTML = jst.getCell(1, 'desc');
$('r2').innerHTML = jst.getCell(1, 1);
- jst.setCell(0, 'desc', 'TEST1');
- jst.setCell(2, 0, 'TEST2');
+ jst.setCell(0, 'desc', 'TEST1').setCell(2, 0, 'TEST2');
$('t2').innerHTML = jst.toJson();
@@ -106,6 +103,10 @@
added: function() {
$('s3').innerHTML = '+'
+ },
+
+ clear_table: function() {
+ this.jst.clear();
}
}
@@ -129,6 +130,7 @@
<input type='button' value='delete' onclick='Ui.delete_row.bind(Ui)()'>
<input type='button' value='delete last' onclick='Ui.delete_last.bind(Ui)()'>
<input type='button' value='add row' onclick='Ui.add_row.bind(Ui)()'>
+ <input type='button' value='clear' onclick='Ui.clear_table.bind(Ui)()'>
</div>
<div>
Please sign in to comment.
Something went wrong with that request. Please try again.