Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move Rows up and down in html table [duplicate]

Possible Duplicate:
Swapping rows in JQuery

How to move rows up and down in a table on some button click?

like image 849
Manthan Avatar asked Dec 01 '10 04:12

Manthan


1 Answers

Try using jQuery. You can do something like:

<table id="mytable">
    <tr>
        <td>row 1</td>
        <td><input type="button" value="move up" class="move up" /></td>
        <td><input type="button" value="move down" class="move down" /></td>
    </tr>
    ...
</table>

$('#mytable input.move').click(function() {
    var row = $(this).closest('tr');
    if ($(this).hasClass('up'))
        row.prev().before(row);
    else
        row.next().after(row);
});

Look at it working here.

You can also try jQuery's sortable, it is much easier.

like image 182
cambraca Avatar answered Sep 23 '22 04:09

cambraca