If I have a table as shown below, and have a up and down arrow that moves rows up and down, how would I go about swapping rows in JQuery?
-
Here is the code to swap the rows. Lets take #Row1 and #Row3
$('#Row1').replaceWith($('#Row3').after($('#Row1').clone(true)));
The clone(true) is used so that events are also taken into account.
If you want to move row up and down then use this code.
To move row UP
var tableRow = $("#Row1");
tableRow.insertBefore(tableRow.prev());
To move row DOWN
var tableRow = $("#Row1");
tableRow.insertAfter(tableRow.next());
讨论(0)
-
I am using drag and drop plugin for swap cathegories in table (with subcathegories), and after not working. insertAfter works.
similiar topic
讨论(0)
-
Here's another solution.
To move a row down:
jQuery("#rowid").next().after(jQuery("#rowid"));
To move a row up:
jQuery("#rowid").prev().before(jQuery("#rowid"));
讨论(0)
-
$("#Row1").after($("#Row2"));
will work
讨论(0)
- 热议问题