move table rows up and down

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
rathika
Forum Newbie
Posts: 1
Joined: Fri Feb 26, 2010 5:15 am

move table rows up and down

Post by rathika »

Hai ,
I have a table in php where the rows are displayed dynamically.
I need to move the rows up and down according to the click.How can i get this?I tried with innerHtml also. But I am unable to get the solution.
Regards
Anu
wpsd2006
Forum Commoner
Posts: 66
Joined: Wed Jan 07, 2009 12:43 am

Re: move table rows up and down

Post by wpsd2006 »

After sorting in php array ( if you use one ) refresh the whole table --- if your apps is localhost you hardly see the delay

IF you use js prototype you can use library scriptaculous it has a sort function ( the cool one )

innerHTML should work too.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

I think you could use something like this:

Code: Select all

var my_table = document.getElementById('my_table');
temp1 = my_table.getElementsByTagName('tr')[the_desired_row].innerHTML;
my_table.getElementsByTagName('tr')[the_desired_row].innerHTML = my_table.getElementsByTagName('tr')[the_other_desired_row].innerHTML;
my_table.getElementsByTagName('tr')[the_other_desired_row].innerHTML = temp1;
This exchanges row [the_desired_row] with [the_other_desired_row].
webadmin40
Forum Newbie
Posts: 5
Joined: Wed Jul 21, 2010 4:07 am

Re: move table rows up and down

Post by webadmin40 »

@ Jonah Bron: Sincere thanks. I had been facing almost a similar problem since a long time. I searched for solutions almost everywhere but this was no help. This one piece of code worked wonders for me. It was so important for me to shift the table rows up and down and i just can't tell you how relieved i am after getting a solution to this. Keep up the good work. Cheers..!!
Post Reply