Browse Source

add events

zhixin 12 years ago
parent
commit
f56b8c0be6
2 changed files with 27 additions and 4 deletions
  1. 13 2
      bootstrap-table.js
  2. 14 2
      index.html

+ 13 - 2
bootstrap-table.js

@@ -23,6 +23,7 @@
 			this.$el.append(this.$header);
 			this.$body = $('<tbody></tbody>');
 			this.$el.append(this.$body);
+			this.data = [];
 			
 			this.initHeader();
 			this.initBody();
@@ -67,6 +68,15 @@
 				html.push('</tr>');
 			});
 			this.$body[append ? 'append' : 'html'](html.join(''));
+			
+			if (append) {
+				this.data = this.data.concat(data);
+			} else {
+				this.data = data || this.options.data;
+			}
+			this.$body.find('tr').click(function() {
+				that.options.onClickRow(that.data[$(this).index()]);
+			});
 		},
 		
 		load: function(data) {
@@ -109,8 +119,9 @@
 	};
 	
 	$.fn.bootstrapTable.defaults = {
-		class: 'table table-striped table-bordered',
+		class: 'table table-bordered table-hover',
 		columns: [],
-		data: []
+		data: [],
+		onClickRow: function() {return false;}
 	};
 })(jQuery);

+ 14 - 2
index.html

@@ -14,6 +14,8 @@
       <table id="table"></table>
       <h3>Column Properties:</h3>
       <table id="column"></table>
+      <h3>Events:</h3>
+      <table id="event"></table>
       <h3>Methods:</h3>
       <table id="method"></table>
     </div>
@@ -31,7 +33,7 @@
             {field: 'default', title: 'Default', align: 'right', width: 180}
           ],
           data: [
-            {name: 'class', type: 'String', description: 'The table class', default: 'table table-striped table-bordered'},
+            {name: 'class', type: 'String', description: 'The table class', default: 'table table-bordered table-hover'},
             {name: 'columns', type: 'Array', description: 'The table columns config object, see column properties for more details.', default: '[]'},
             {name: 'data', type: 'Array', description: 'The data to be loaded.', default: '[]'}
           ]
@@ -48,7 +50,17 @@
             {name: 'title', type: 'String', description: 'The column title text.', default: 'undefined'},
             {name: 'align', type: 'String', description: 'Indicate how to align the column data. "left", "right", "center" can be used.', default: 'undefined'},
             {name: 'width', type: 'Number', description: 'The width of column. If not defined, the width will auto expand to fit its contents.', default: 'undefined'},
-            {name: 'formatter', type: 'Function', description: 'The cell formatter function, take two parameters: <br />value: the field value. <br />rowData: the row record data.', default: 'undefined'}
+            {name: 'formatter', type: 'Function', description: 'The cell formatter function, take two parameters: <br />value: the field value. <br />row: the row record data.', default: 'undefined'}
+          ]
+        });
+        $('#event').bootstrapTable({
+          columns: [
+            {field: 'name', title: 'Name', align: 'center', width: 100},
+            {field: 'parameter', title: 'Parameter', align: 'center', width: 100},
+            {field: 'description', title: 'Description', width: 400}
+          ],
+          data: [
+            {name: 'onClickRow', parameter: 'row', description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row'}
           ]
         });
         $('#method').bootstrapTable({