Home Search Member List Faq Register Login  
JavaScript Tips
Swap table rows on the client-side

Thread Starter: Karamasoft   Started: 09-04-2007 7:10 PM   Replies: 0
 Karamasoft Support Forums » General Discussions » JavaScript Tips » Swap table rows on the client-side
 Printable Version    « Previous Thread   Next Thread »
  04 Sep 2007, 7:10 PM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Swap table rows on the client-side

You can swap table rows on the client-side by swapping the cell contents of the current rows and the row to swap. The following method takes three parameters: the current table row element, a Boolean to indicate whether the row should move up, and a Boolean to indicate whether the first row should be ignored.

function SwapRows(rowElem, dirUp, ignoreFirstRow) {
 var rowElemToSwap = (dirUp) ? rowElem.previousSibling : rowElem.nextSibling;

 // Firefox returns a blank text node for the sibling
 while (rowElemToSwap && rowElemToSwap.nodeType != 1) {
  rowElemToSwap = (dirUp) ? rowElemToSwap.previousSibling : rowElemToSwap.nextSibling;
 }

 if (rowElemToSwap && !(ignoreFirstRow && rowElemToSwap.rowIndex == 0)) {
  var rowCells = rowElem.cells;
  var colInner;
  for (var i = 0, loopCnt = rowCells.length; i < loopCnt; i++) {
   colInner = rowCellsIdea.innerHTML;
   rowCellsIdea.innerHTML = rowElemToSwap.cellsIdea.innerHTML;
   rowElemToSwap.cellsIdea.innerHTML = colInner;
  }
 }
}


  
 Page 1 of 1 (1 items)
Karamasoft Support Forums » General Discussions » JavaScript Tips » Swap table rows on the client-side

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.