Hi Paul,

This will do the trick, but it could be written a lot more elegantly (it's midnight here, and I only had a few minutes to bang something out):

    $(document).ready(function() {
      $('tr:first-child .moveup').hide();
      $('tr:last-child .movedown').hide();

      $('a.moveup').click(function(event) {
        var $thisRow = $(this).parents('tr:first');
        $thisRow.insertBefore( $thisRow.prev() );

        if ($thisRow.is(':first-child')) {
          $thisRow.find('.moveup').hide();
          $thisRow.next().find('.moveup').show();
        }
        return false;
      });
      $('a.movedown').click(function(event) {
        var $thisRow = $(this).parents('tr:first');
        $thisRow.insertAfter( $thisRow.next() );
        if ($thisRow.is(':last-child')) {
          $thisRow.find('.movedown').hide();
          $thisRow.prev().find('.movedown').show();
        }
        return false;
      });
    });

There's a lot of repetitive code there. Sorry about that. Use it as a starting point.

--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Jun 14, 2009, at 10:21 PM, Paul Witschger wrote:

actually, there is one problem. I guess what I need is something a little different.

Basically the same, but I need to know if the row is at the end or beginning of the list. If a row is moving into the first spot, I need to remove the "Move Up" link. Same with the row moving down (removing "Move Down" link if last row).

Is there a way to check for this?

Thanks

John Bill wrote:

good job!

2009/6/15 Paul Witschger <tigerseyet...@gmail.com>
Thank you, Karl!!

Works excellent. Exactly what I needed!




Karl Swedberg wrote:

Assuming that the Move Up link is within the table row and that the link has a class of "moveup," you could do something like this:


$('a.moveup').click(function() {
  var $thisRow = $(this).parents('tr:first');
  $thisRow.insertBefore( $thisRow.prev() );
  return false;
});

--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Jun 14, 2009, at 6:36 PM, theprodigy wrote:


I am creating an admin section for a site I'm building. One of the
options is to change the sort order of a list of items. I have all the
backend (PHP) code running properly, but having a little issue with
the jQuery.

When the user clicks the Move Up link, how can I switch the table row
containing the link they clicked on, and the one above it (row 3
becomes 2, and row 2 becomes 3)?

Thanks




Reply via email to