浏览代码

Fix bug: sorter does not work in some case.

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

+ 11 - 5
src/bootstrap-table.js

@@ -366,9 +366,10 @@
         this.$header.find('tr').html(html.join(''));
         this.$header.find('tr').html(html.join(''));
         this.$header.find('th').each(function (i) {
         this.$header.find('th').each(function (i) {
             $(this).data(visibleColumns[i]);
             $(this).data(visibleColumns[i]);
-
-            if (that.options.sortable && visibleColumns[i].sortable) {
-                $(this).off('click').on('click', $.proxy(that.onSort, that));
+        });
+        this.$container.off('click', 'th').on('click', 'th', function (event) {
+            if (that.options.sortable && $(this).data().sortable) {
+                that.onSort(event);
             }
             }
         });
         });
 
 
@@ -1076,7 +1077,7 @@
             return;
             return;
         }
         }
 
 
-        this.$header_ = this.$header.clone(true);
+        this.$header_ = this.$header.clone(true, true);
         this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
         this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
 
 
         // fix bug: get $el.css('width') error sometime (height = 500)
         // fix bug: get $el.css('width') error sometime (height = 500)
@@ -1089,12 +1090,17 @@
                 .html('').attr('class', that.$el.attr('class'))
                 .html('').attr('class', that.$el.attr('class'))
                 .append(that.$header_);
                 .append(that.$header_);
 
 
-            that.$el.css('margin-top', -that.$header.height());
+            // fix bug: $.data() is not working as expected after $.append()
+            that.$header.find('th').each(function (i) {
+                that.$header_.find('th').eq(i).data($(this).data());
+            });
 
 
             that.$body.find('tr:first-child:not(.no-records-found) > *').each(function(i) {
             that.$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());
             });
             });
 
 
+            that.$el.css('margin-top', -that.$header.height());
+
             // horizontal scroll event
             // horizontal scroll event
             $fixedBody.off('scroll').on('scroll', function () {
             $fixedBody.off('scroll').on('scroll', function () {
                 $fixedHeader.scrollLeft($(this).scrollLeft());
                 $fixedHeader.scrollLeft($(this).scrollLeft());