UNPKG

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