Page 1 of 1

move table rows up and down

Posted: Fri Feb 26, 2010 6:49 am
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

Re: move table rows up and down

Posted: Fri Feb 26, 2010 10:34 am
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.

Posted: Sun Feb 28, 2010 7:31 pm
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].

Re: move table rows up and down

Posted: Thu Aug 05, 2010 12:34 pm
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..!!