You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7 KiB

  1. (function($) {
  2. $.fn.resizableColumns = function() {
  3. var isColResizing = false;
  4. var resizingPosX = 0;
  5. var _table = $(this);
  6. var _thead = $(this).find('thead');
  7. _thead.find('th').each(function() {
  8. $(this).css('position', 'relative');
  9. if ($(this).is(':not(:last-child)')) $(this).append("<div class='resizer' style='position:absolute;top:0px;right:-3px;bottom:0px;width:6px;z-index:999;background:transparent;cursor:col-resize'></div>");
  10. })
  11. $(document).mouseup(function(e) {
  12. _thead.find('th').removeClass('resizing');
  13. isColResizing = false;
  14. e.stopPropagation();
  15. })
  16. _table.find('.resizer').mousedown(function(e) {
  17. _thead.find('th').removeClass('resizing');
  18. $(_thead).find('tr:first-child th:nth-child(' + ($(this).closest('th').index() + 1) + ') .resizer').closest('th').addClass('resizing');
  19. resizingPosX = e.pageX;
  20. isColResizing = true;
  21. e.stopPropagation();
  22. })
  23. _table.mousemove(function(e) {
  24. if (isColResizing) {
  25. var _resizing = _thead.find('th.resizing .resizer');
  26. if (_resizing.length == 1) {
  27. var _nextRow = _thead.find('th.resizing + th');
  28. var _pageX = e.pageX || 0;
  29. var _widthDiff = _pageX - resizingPosX;
  30. var _setWidth = _resizing.closest('th').innerWidth() + _widthDiff;
  31. var _nextRowWidth = _nextRow.innerWidth() - _widthDiff;
  32. if (resizingPosX != 0 && _widthDiff != 0 && _setWidth > 50 && _nextRowWidth > 50) {
  33. _resizing.closest('th').innerWidth(_setWidth);
  34. resizingPosX = e.pageX;
  35. _nextRow.innerWidth(_nextRowWidth);
  36. }
  37. }
  38. }
  39. })
  40. };
  41. }
  42. (jQuery));