ソースを参照

Fix double header bug after timeout.

zhixin 10 年 前
コミット
a6b1ec641f
1 ファイル変更13 行追加14 行削除
  1. 13 14
      src/bootstrap-table.js

+ 13 - 14
src/bootstrap-table.js

@@ -617,9 +617,9 @@
 
 
         if (index !== -1) {
         if (index !== -1) {
             this.data.sort(function (a, b) {
             this.data.sort(function (a, b) {
-                if(that.header.sortNames[index]) {
+                if (that.header.sortNames[index]) {
                     name = that.header.sortNames[index];
                     name = that.header.sortNames[index];
-                }            	
+                }
                 var aa = a[name],
                 var aa = a[name],
                     bb = b[name],
                     bb = b[name],
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
@@ -1483,12 +1483,10 @@
     };
     };
 
 
     BootstrapTable.prototype.resetHeader = function () {
     BootstrapTable.prototype.resetHeader = function () {
-        this.$el.css('margin-top', -this.$header.height());
         // fix #61: the hidden table reset header bug.
         // fix #61: the hidden table reset header bug.
         // fix bug: get $el.css('width') error sometime (height = 500)
         // fix bug: get $el.css('width') error sometime (height = 500)
         clearTimeout(this.timeoutId_);
         clearTimeout(this.timeoutId_);
         this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
         this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
-        return;
     };
     };
 
 
     BootstrapTable.prototype.fitHeader = function () {
     BootstrapTable.prototype.fitHeader = function () {
@@ -1501,24 +1499,25 @@
             that.timeoutFooter_ = setTimeout($.proxy(that.fitHeader, that), 100);
             that.timeoutFooter_ = setTimeout($.proxy(that.fitHeader, that), 100);
             return;
             return;
         }
         }
-        $fixedHeader = that.$container.find('.fixed-table-header'),
-            $fixedBody = that.$container.find('.fixed-table-body'),
-            scrollWidth = that.$el.width() > $fixedBody.width() ? getScrollBarWidth() : 0;
+        $fixedHeader = this.$container.find('.fixed-table-header');
+        $fixedBody = this.$container.find('.fixed-table-body');
+        scrollWidth = this.$el.width() > $fixedBody.width() ? getScrollBarWidth() : 0;
 
 
-        that.$header_ = that.$header.clone(true, true);
-        that.$selectAll_ = that.$header_.find('[name="btSelectAll"]');
+        this.$el.css('margin-top', -this.$header.height());
+        this.$header_ = this.$header.clone(true, true);
+        this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
         $fixedHeader.css({
         $fixedHeader.css({
             'margin-right': scrollWidth
             'margin-right': scrollWidth
-        }).find('table').css('width', that.$el.css('width'))
-            .html('').attr('class', that.$el.attr('class'))
-            .append(that.$header_);
+        }).find('table').css('width', this.$el.css('width'))
+            .html('').attr('class', this.$el.attr('class'))
+            .append(this.$header_);
 
 
         // fix bug: $.data() is not working as expected after $.append()
         // fix bug: $.data() is not working as expected after $.append()
-        that.$header.find('th').each(function (i) {
+        this.$header.find('th').each(function (i) {
             that.$header_.find('th').eq(i).data($(this).data());
             that.$header_.find('th').eq(i).data($(this).data());
         });
         });
 
 
-        that.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
+        this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
             that.$header_.find('div.fht-cell').eq(i).width($(this).innerWidth());
             that.$header_.find('div.fht-cell').eq(i).width($(this).innerWidth());
         });
         });
         // horizontal scroll event
         // horizontal scroll event