Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added events for cell edit row add and row delete.

  • Loading branch information...
commit dc927f97db1a4bccdffa74e408c99da198f12c72 1 parent 4d6f419
@reednj authored
Showing with 32 additions and 1 deletion.
  1. +9 −0 Source/jsTable.js
  2. +23 −1 Test/test.html
View
9 Source/jsTable.js
@@ -9,6 +9,10 @@ var jsTable = new Class({
this.element = $(elem);
this.options = options || {};
+ this.options.onRowDeleted = this.options.onRowDeleted || $empty;
+ this.options.onRowAdded = this.options.onRowAdded || $empty;
+ this.options.onCellUpdated = this.options.onCellUpdated || $empty;
+
this.thead = null;
this.tbody = null;
@@ -125,6 +129,7 @@ var jsTable = new Class({
this.row_list.push(this.data.length);
this.data.push(row_data);
+ this.options.onRowAdded(this.data.length-1, row_data);
},
deleteRow: function(row_index) {
@@ -136,6 +141,8 @@ var jsTable = new Class({
this.data.erase(row_data);
$(tr_id).dispose();
+ this.options.onRowDeleted(row_index, row_id);
+
},
deleteRowById: function(row_id) {
@@ -167,6 +174,8 @@ var jsTable = new Class({
}
this.data[row_id][column_id] = cell_content;
+
+ this.options.onCellUpdated(row_id, column_id, cell_content);
},
toData: function(format) {
View
24 Test/test.html
@@ -18,7 +18,11 @@
var Ui = {
init: function() {
- this.jst = new jsTable('t1');
+ this.jst = new jsTable('t1', {
+ 'onRowDeleted': this.deleted,
+ 'onRowAdded': this.added,
+ 'onCellUpdated': this.updated
+ });
var jst = this.jst;
jst.addColumn('id', 'id');
@@ -53,6 +57,18 @@
delete_last: function() {
this.jst.deleteRow(this.jst.rowCount()-1);
+ },
+
+ deleted: function(row_index) {
+ $('s1').innerHTML = '+'
+ },
+
+ updated: function() {
+ $('s2').innerHTML = '+'
+ },
+
+ added: function() {
+ $('s3').innerHTML = '+'
}
}
@@ -73,6 +89,12 @@
<span>get cell by name:</span>
<span id='r1'> </span>
</div>
+
+ <div>
+ <span>deletes: </span> <span id='s1'> </span>
+ <span>update: </span> <span id='s2'> </span>
+ <span>adds: </span> <span id='s3'> </span>
+ </div>
<div>
<span>get cell by column_id:</span>
Please sign in to comment.
Something went wrong with that request. Please try again.