Pu Zhibing
2025-02-19 81e2eb4dd2e27da3c4cc447d6aeb9150a5ff7464
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * @author: Dennis Hernández
 * @version: v2.0.0
 */
 
const isInit = that => that.$el.data('resizableColumns') !== undefined
 
const initResizable = that => {
  if (
    that.options.resizable &&
    !that.options.cardView &&
    !isInit(that) &&
    that.$el.is(':visible')
  ) {
    that.$el.resizableColumns({
      store: window.store
    })
  }
}
 
const destroy = that => {
  if (isInit(that)) {
    that.$el.data('resizableColumns').destroy()
  }
}
 
const reInitResizable = that => {
  destroy(that)
  initResizable(that)
}
 
Object.assign($.fn.bootstrapTable.defaults, {
  resizable: false
})
 
$.BootstrapTable = class extends $.BootstrapTable {
 
  initBody (...args) {
    super.initBody(...args)
 
    this.$el.off('column-switch.bs.table page-change.bs.table')
      .on('column-switch.bs.table page-change.bs.table', () => {
        reInitResizable(this)
      })
 
    reInitResizable(this)
  }
 
  toggleView (...args) {
    super.toggleView(...args)
 
    if (this.options.resizable && this.options.cardView) {
      // Destroy the plugin
      destroy(this)
    }
  }
 
  resetView (...args) {
    super.resetView(...args)
 
    if (this.options.resizable) {
      // because in fitHeader function, we use setTimeout(func, 100);
      setTimeout(() => {
        initResizable(this)
      }, 100)
    }
  }
}