Advertisement
Guest User

DataTables ColReorder whole column move

a guest
Apr 30th, 2020
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "_fnCreateDragNode": function ()
  2. {
  3.     var scrolling = this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "";
  4.  
  5.     var origCell = this.s.dt.aoColumns[ this.s.mouse.targetIndex ].nTh;
  6.     var origTr = origCell.parentNode;
  7.     var origThead = origTr.parentNode;
  8.     var origTbody = origThead.nextElementSibling; // NEW CODE
  9.     var origTable = origThead.parentNode;
  10.     var cloneCell = $(origCell).clone();
  11.     var columnIndex = $(origCell).index(); // NEW CODE
  12.  
  13.     // NEW CODE START
  14.     var newTbody = $(origTbody.cloneNode(false));
  15.     Array.prototype.forEach.call(origTbody.children, function(origTbodyTr, i) {
  16.         newTbody.append($(origTbodyTr.cloneNode(false)).append(
  17.             $(origTbodyTr.children[columnIndex]).clone()[0]
  18.         ));
  19.     });
  20.     // NEW CODE END
  21.  
  22.     // This is a slightly odd combination of jQuery and DOM, but it is the
  23.     // fastest and least resource intensive way I could think of cloning
  24.     // the table with just a single header cell in it.
  25.     this.dom.drag = $(origTable.cloneNode(false))
  26.         .addClass( 'DTCR_clonedTable' )
  27.         .append(
  28.             $(origThead.cloneNode(false)).append(
  29.                 $(origTr.cloneNode(false)).append(
  30.                     cloneCell[0]
  31.                 )
  32.             )
  33.         ).append( // NEW CODE
  34.             newTbody // NEW CODE
  35.         ).css( {
  36.             position: 'absolute',
  37.             top: 0,
  38.             left: 0,
  39.             width: $(origCell).outerWidth()
  40.             // REMOVED HEIGHT SETTING
  41.         } )
  42.         .appendTo( 'body' );
  43.  
  44.     this.dom.pointer = $('<div></div>')
  45.         .addClass( 'DTCR_pointer' )
  46.         .css( {
  47.             position: 'absolute',
  48.             top: scrolling ?
  49.                 $('div.dataTables_scroll', this.s.dt.nTableWrapper).offset().top :
  50.                 $(this.s.dt.nTable).offset().top,
  51.             height : scrolling ?
  52.                 $('div.dataTables_scroll', this.s.dt.nTableWrapper).height() :
  53.                 $(this.s.dt.nTable).height()
  54.         } )
  55.         .appendTo( 'body' );
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement