Browse Source

Fixed the resize problem with multiple tables

zhixin 6 years ago
parent
commit
ec28704484
3 changed files with 6 additions and 3 deletions
  1. 0 2
      site/docs/api/table-options.md
  2. 1 1
      src/bootstrap-table.js
  3. 5 0
      src/utils/index.js

+ 0 - 2
site/docs/api/table-options.md

@@ -37,8 +37,6 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
   The height of table, enable fixed header of table.
 
-  Note that if there are multiple tables on a page and the height option is set at the same time, you need to add the `id` attribute to each table, otherwise, the window resize will not work properly.
-
 - **Default:** `undefined`
 
 - **Example:** [Table Height](https://examples.bootstrap-table.com/#options/table-height.html)

+ 1 - 1
src/bootstrap-table.js

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

+ 5 - 0
src/utils/index.js

@@ -312,5 +312,10 @@ export default {
     }
 
     return order
+  },
+
+  getResizeEventName (id = '') {
+    id = id || `${+new Date()}${~~(Math.random() * 1000000)}`
+    return `resize.bootstrap-table-${id}`
   }
 }