浏览代码

Merge pull request #5191 from wenzhixin/fix/5186

Fixed resize and scroll event
Dustin Utecht 5 年之前
父节点
当前提交
e54e3ca10b
共有 3 个文件被更改,包括 8 次插入7 次删除
  1. 1 1
      src/bootstrap-table.js
  2. 5 4
      src/extensions/sticky-header/bootstrap-table-sticky-header.js
  3. 2 2
      src/utils/index.js

+ 1 - 1
src/bootstrap-table.js

@@ -375,7 +375,7 @@ class BootstrapTable {
       }
     })
 
-    const resizeEvent = Utils.getResizeEventName(this.$el.attr('id'))
+    const resizeEvent = Utils.getEventName('resize.bootstrap-table', this.$el.attr('id'))
     $(window).off(resizeEvent)
     if (!this.options.showHeader || this.options.cardView) {
       this.$header.hide()

+ 5 - 4
src/extensions/sticky-header/bootstrap-table-sticky-header.js

@@ -36,10 +36,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
     this.$stickyHeader = this.$header.clone(true, true)
 
     // render sticky on window scroll or resize
-    $(window).off('resize.sticky-header-table')
-      .on('resize.sticky-header-table', () => this.renderStickyHeader())
-    $(window).off('scroll.sticky-header-table')
-      .on('scroll.sticky-header-table', () => this.renderStickyHeader())
+    const resizeEvent = Utils.getEventName('resize.sticky-header-table', this.$el.attr('id'))
+    const scrollEvent = Utils.getEventName('scroll.sticky-header-table', this.$el.attr('id'))
+
+    $(window).off(resizeEvent).on(resizeEvent, () => this.renderStickyHeader())
+    $(window).off(scrollEvent).on(scrollEvent, () => this.renderStickyHeader())
     this.$tableBody.off('scroll').on('scroll', () => this.matchPositionX())
   }
 

+ 2 - 2
src/utils/index.js

@@ -333,9 +333,9 @@ export default {
     return order
   },
 
-  getResizeEventName (id = '') {
+  getEventName (eventPrefix, id = '') {
     id = id || `${+new Date()}${~~(Math.random() * 1000000)}`
-    return `resize.bootstrap-table-${id}`
+    return `${eventPrefix}-${id}`
   },
 
   hasDetailViewIcon (options) {