ソースを参照

add height property.

zhixin 12 年 前
コミット
996e8b1142
2 ファイル変更16 行追加8 行削除
  1. 2 3
      index.html
  2. 14 5
      jquery.bootstrap.table.js

+ 2 - 3
index.html

@@ -18,9 +18,6 @@
       body {
         padding-bottom: 60px;
       }
-      #example {
-        height: 200px;
-      }
     </style>
   </head>
   <body data-spy="scroll" data-target=".bs-docs-sidebar">
@@ -84,6 +81,7 @@
             {field: 'default', title: 'Default', align: 'right', width: 180}
           ],
           data: [
+            {name: 'height', type: 'Number', description: 'The height of table.', 'default': 'undefined'},
             {name: 'sortName', type: 'String', description: 'Defines which column can be sorted.', 'default': 'undefined'},
             {name: 'sortOrder', type: 'String', description: 'Defines the column sort order, can only be "asc" or "desc".', 'default': 'asc'},
             {name: 'columns', type: 'Array', description: 'The table columns config object, see column properties for more details.', 'default': '[]'},
@@ -158,6 +156,7 @@
           data.push({code: '' + i, name: 'hello ' + i, price: '$' + i});
         }
         $('#example').bootstrapTable({
+          height: 200,
           sortName: 'code',
           sortOrder: 'asc',
           columns: [

+ 14 - 5
jquery.bootstrap.table.js

@@ -17,6 +17,8 @@
 		constructor: Table,
 		
 		init: function(options, first) {
+			this.options = options;
+
 			if (first) {
 				this.$div = $([
 					'<div class="fixed-table-container">',
@@ -25,13 +27,11 @@
 					'</div>'].join(''));
 				this.$div.insertAfter(this.$el);
 				this.$div.find('.fixed-table-body').append(this.$el);
-				if (this.$el.height()) {
-					this.$div.css('height', this.$el.height() + 'px');
+				if (this.options.height) {
+					this.$div.css('height', this.options.height + 'px');
 				}
 				this.$el.addClass('table table-hover');
 			}
-			
-			this.options = options;
 			this.$el.html('');
 			this.$header = $('<thead></thead>');
 			this.$el.append(this.$header);
@@ -66,7 +66,7 @@
 				that.header.formatters.push(column.formatter);
 				that.header.sorters.push(column.sorter);
 				
-				style += column.width ? 'width: ' + column.width + 'px; ': '';
+				style = column.width ? 'width: ' + column.width + 'px; ': '';
 				style += column.sortable ? 'cursor: pointer;' : '';
 				
 				html.push('<th' + 
@@ -140,6 +140,7 @@
 			this.$body.find('tr').click(function() {
 				that.options.onClickRow(that.data[$(this).index()]);
 			});
+			this.resetView();
 		},
 		
 		onSort: function($this) {
@@ -159,6 +160,14 @@
 				'</span>'].join('');
 		},
 		
+		resetView: function() {
+			var that = this;
+			this.$header.find('.th-inner').each(function(i) {
+				$(this).attr('style', that.header.styles[i])
+					.css('width', ($(this).parent().width() - 16) + 'px'); // padding: 8px
+			});
+		},
+		
 		/** public function **/
 		
 		load: function(data) {