bootstrap-table-resizable.js 2.1 KB

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