Move/Rearrange HTML table rows

September 10, 2010 at 3:30 am Leave a comment

A simple javascript solution for moving html table rows up/down on click of an image.

function moveUp(node){

var changeNode;

var parent;

if(node.rowIndex!=0){

changeNode=getNextRow(-1,node.rowIndex);

parent = node.parentNode;

parent.insertBefore(node,changeNode);

}

}

function moveDown(node){

var changeNode;

var parent;

var ln = document.getElementById(“myTable”).rows.length;

if(node.rowIndex!=ln-1){

changeNode=getNextRow(1,node.rowIndex);

parent = node.parentNode;

parent.insertBefore(changeNode,node);

}

}

function getNextRow(diff,selectedRowIndex){

var table = document.getElementById(“myTable”);

var cnt;

for (var i = 0, row; row = table.rows[i]; i ++) {

if(row.rowIndex==selectedRowIndex){

cnt = i+diff;

return table.rows[cnt];

}

}

}

First Row Up Down
Second Row Up Down
Third Row Up Down
Fourth Row Up Down


~HTH

Advertisement

Entry filed under: tips and tricks. Tags: , .

Samsung Jet S8003 . Add / Remove from Reject List Java , Unix & Spanish Characters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

September 2010
M T W T F S S
« May   Oct »
 12345
6789101112
13141516171819
20212223242526
27282930  

Follow

Get every new post delivered to your Inbox.