UNPKG

1.62 kBJavaScriptView Raw
1/**
2 * @author: Dennis Hernández
3 * @webSite: http://djhvscf.github.io/Blog
4 * @version: v2.0.0
5 */
6
7const isInit = that => that.$el.data('resizableColumns') !== undefined
8
9const initResizable = that => {
10 if (that.options.resizable && !that.options.cardView && !isInit(that)) {
11 that.$el.resizableColumns()
12 }
13}
14
15const destroy = that => {
16 if (isInit(that)) {
17 that.$el.data('resizableColumns').destroy()
18 }
19}
20
21const reInitResizable = that => {
22 destroy(that)
23 initResizable(that)
24}
25
26$.extend($.fn.bootstrapTable.defaults, {
27 resizable: false
28})
29
30const BootstrapTable = $.fn.bootstrapTable.Constructor
31const _initBody = BootstrapTable.prototype.initBody
32const _toggleView = BootstrapTable.prototype.toggleView
33const _resetView = BootstrapTable.prototype.resetView
34
35BootstrapTable.prototype.initBody = function (...args) {
36 const that = this
37 _initBody.apply(this, Array.prototype.slice.apply(args))
38
39 that.$el
40 .off('column-switch.bs.table, page-change.bs.table')
41 .on('column-switch.bs.table, page-change.bs.table', () => {
42 reInitResizable(that)
43 })
44}
45
46BootstrapTable.prototype.toggleView = function (...args) {
47 _toggleView.apply(this, Array.prototype.slice.apply(args))
48
49 if (this.options.resizable && this.options.cardView) {
50 // Destroy the plugin
51 destroy(this)
52 }
53}
54
55BootstrapTable.prototype.resetView = function (...args) {
56 const that = this
57
58 _resetView.apply(this, Array.prototype.slice.apply(args))
59
60 if (this.options.resizable) {
61 // because in fitHeader function, we use setTimeout(func, 100);
62 setTimeout(() => {
63 initResizable(that)
64 }, 100)
65 }
66}