bootstrap-table-resizable.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @author: Dennis Hernández
  3. * @webSite: http://djhvscf.github.io/Blog
  4. * @version: v1.0.0
  5. */
  6. (function ($) {
  7. 'use strict';
  8. var initResizable = function (that) {
  9. //Deletes the plugin to re-create it
  10. that.$el.colResizable({disable: true});
  11. //Creates the plugin
  12. that.$el.colResizable({
  13. liveDrag: that.options.liveDrag,
  14. fixed: that.options.fixed,
  15. headerOnly: that.options.headerOnly,
  16. minWidth: that.options.minWidth,
  17. hoverCursor: that.options.hoverCursor,
  18. dragCursor: that.options.dragCursor,
  19. onResize: that.onResize,
  20. onDrag: that.options.onResizableDrag,
  21. resizeMode: that.options.resizeMode
  22. });
  23. };
  24. $.extend($.fn.bootstrapTable.defaults, {
  25. resizable: false,
  26. liveDrag: false,
  27. fixed: true,
  28. headerOnly: false,
  29. minWidth: 15,
  30. hoverCursor: 'e-resize',
  31. dragCursor: 'e-resize',
  32. onResizableResize: function (e) {
  33. return false;
  34. },
  35. onResizableDrag: function (e) {
  36. return false;
  37. }
  38. });
  39. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  40. _toggleView = BootstrapTable.prototype.toggleView,
  41. _resetView = BootstrapTable.prototype.resetView;
  42. BootstrapTable.prototype.toggleView = function () {
  43. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  44. if (this.options.resizable && this.options.cardView) {
  45. //Deletes the plugin
  46. $(this.$el).colResizable({disable: true});
  47. }
  48. };
  49. BootstrapTable.prototype.resetView = function () {
  50. var that = this;
  51. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  52. if (this.options.resizable) {
  53. // because in fitHeader function, we use setTimeout(func, 100);
  54. setTimeout(function () {
  55. initResizable(that);
  56. }, 100);
  57. }
  58. };
  59. BootstrapTable.prototype.onResize = function (e) {
  60. var that = $(e.currentTarget);
  61. that.bootstrapTable('resetView');
  62. that.data('bootstrap.table').options.onResizableResize.apply(e);
  63. }
  64. })(jQuery);