Wednesday, April 21, 2010

Cutting edge table rows reorder control

By Neelesh Salpe


Problem with firefox is that it does not support DOM method
table is element .
table.moveRow(fromIndex, toIndex);


There is work arround for this

JS mthods after clicking on " Move Up method "
You can infer method for "Move Down " from above example.



function moveUpRow(tableId) {
var fromindex = null;

var trs = document.getElementById(tableId)
.getElementsByTagName('tbody')[0].getElementsByTagName('tr');


for ( var i = 0; i < classname ="=" fromindex =" i;"> 0){

var table = document.getElementById(tableId);

moveRow(table,(parseInt(fromindex) - 1),parseInt(fromindex));
moveUp(fromindex);
}

}







function moveRow(table, from, to)
{
var tbody = table.tBodies[0]; // Use tbody
var trFrom = tbody.rows[from]; // Make sure row stays referenced
tbody.removeChild(trFrom); // Remove the row before inserting it (dupliate id's etc.)
var trTo = tbody.rows[to];
tbody.insertBefore(trFrom, trTo);
}



Above code is working and tested for IE8, firewfox3.5 , safari , opera


No comments: