Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Well, I had a little free time to kill, it being my birthday and all. So, I decided to update my moveRow prototype that mimics the IE only function. Here's IE's page of it. Click.

What's new in this version are the following:
  • Fixed the bug of not copying attributes to the new row
  • Fixed the bug in Opera of the cells merging
  • Removed the unneeded try-catch system and replaced the error with a return
  • Extra check to save time
  • Check to create function is done with createElement instead of getElementsByTagName. (Thanks to Peter for the suggestion)


Nothing too special, but something I thought I should mention none the less. For a live preview, click here.


if(typeof document.createElement("table").moveRow == "undefined"){
   function _mR(one,two){
      if(this && this.nodeName.match(/^t(body|able|head|foot)$/i)){
         var one = (one || one === 0?one:-1);
         var two = (two || two === 0?two:-1);

         // Make sure the row exists
         // Make sure the insertable row isn't greater then the length
         // Make sure the row and destination aren't the same
         if(!this.rows[one] || two > this.rows.length || two === one)
            return null;

         // This is just so that it gets put in the right place.
         if(two > one)
            two++;
         else if(one > two && two !== -1)
            one++;

         var newRow = this.insertRow(two);
         while(this.rows[one].firstChild)
            newRow.appendChild(this.rows[one].firstChild);
         for(var a=0;a<this.rows[one].attributes.length;a++){
            var x = this.rows[one].attributes[a];
            newRow.setAttribute(x.nodeName,x.nodeValue);
         }
         this.deleteRow(one);
      }
   }
   HTMLTableElement.prototype.moveRow = _mR;
   HTMLTableSectionElement.prototype.moveRow = _mR;
}


Edit 10/29/06 - I took Peter's advise and updated this for the HTMLTableElement and HTMLTableSectionElement. It now also supports thead and tbody's.



(Copied and pasted from my blog. :P)


Last Edit: Nov 3, 2006 17:59:30 GMT by Chris

newBookmarkLockedFalling