浏览代码

Fix scroll header width error.

zhixin 11 年之前
父节点
当前提交
80da341dfa
共有 1 个文件被更改,包括 13 次插入10 次删除
  1. 13 10
      src/bootstrap-table.js

+ 13 - 10
src/bootstrap-table.js

@@ -940,22 +940,25 @@
         this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
         this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
         this.$el.css('margin-top', -this.$header.height());
         this.$el.css('margin-top', -this.$header.height());
 
 
-        $fixedHeader.css({
+        // fix bug: get $el.css('width') error sometime (height = 500)
+        setTimeout(function () {
+            $fixedHeader.css({
                 'height': '37px',
                 'height': '37px',
                 'border-bottom': '1px solid #dddddd',
                 'border-bottom': '1px solid #dddddd',
                 'margin-right': scrollWidth
                 'margin-right': scrollWidth
             })
             })
-            .find('table').css('width', this.$el.css('width'))
-            .html('').attr('class', this.$el.attr('class'))
-            .append(this.$header_);
+                .find('table').css('width', that.$el.css('width'))
+                .html('').attr('class', that.$el.attr('class'))
+                .append(that.$header_);
 
 
-        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.$body.find('tr:first-child:not(.no-records-found) > *').each(function(i) {
+                that.$header_.find('div.fht-cell').eq(i).width($(this).innerWidth());
+            });
 
 
-        // horizontal scroll event
-        $fixedBody.off('scroll').on('scroll', function () {
-            $fixedHeader.scrollLeft($(this).scrollLeft());
+            // horizontal scroll event
+            $fixedBody.off('scroll').on('scroll', function () {
+                $fixedHeader.scrollLeft($(this).scrollLeft());
+            });
         });
         });
     };
     };