仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ imsetes/js/bootstrap-table/extensions/resizable/bootstrap-table-resizable.js 1.6 KB · 68 行 原始文件
Z zfhsh first commit 2 个月前
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 store: window.store
13 })
14 }
15}
16
17const destroy = that => {
18 if (isInit(that)) {
19 that.$el.data('resizableColumns').destroy()
20 }
21}
22
23const reInitResizable = that => {
24 destroy(that)
25 initResizable(that)
26}
27
28$.extend($.fn.bootstrapTable.defaults, {
29 resizable: false
30})
31
32const BootstrapTable = $.fn.bootstrapTable.Constructor
33const _initBody = BootstrapTable.prototype.initBody
34const _toggleView = BootstrapTable.prototype.toggleView
35const _resetView = BootstrapTable.prototype.resetView
36
37BootstrapTable.prototype.initBody = function (...args) {
38 const that = this
39 _initBody.apply(this, Array.prototype.slice.apply(args))
40
41 that.$el
42 .off('column-switch.bs.table page-change.bs.table')
43 .on('column-switch.bs.table page-change.bs.table', () => {
44 reInitResizable(that)
45 })
46}
47
48BootstrapTable.prototype.toggleView = function (...args) {
49 _toggleView.apply(this, Array.prototype.slice.apply(args))
50
51 if (this.options.resizable && this.options.cardView) {
52 // Destroy the plugin
53 destroy(this)
54 }
55}
56
57BootstrapTable.prototype.resetView = function (...args) {
58 const that = this
59
60 _resetView.apply(this, Array.prototype.slice.apply(args))
61
62 if (this.options.resizable) {
63 // because in fitHeader function, we use setTimeout(func, 100);
64 setTimeout(() => {
65 initResizable(that)
66 }, 100)
67 }
68}