bootstrap-table-resizable.min.js 1.7 KB

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