Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:08:39+00:00 2026-05-31T11:08:39+00:00

I need to move a table row from a position to the first in

  • 0

I need to move a table row from a position to the first in the table and after clicking again to the old position.

I have a list of checkboxes in a table. These are coming from code behind and are already sorted. If I click on a checkbox, I want to move this entry to the begin of the list. If the users unchecks this box or clicks on another box, it shall be moved to the old position.

for better understanding:

 [ ] 1
 [ ] 3
 [ ] A
 [ ] B
 [ ] C

After clicking on e.g. [ ] C:

 [X] C
 [ ] 1
 [ ] 3
 [ ] A
 [ ] B

After clicking on e.g. [ ] 3 C has got the old position and 3 has moved to the top.

 [X] 3
 [ ] 1
 [ ] A
 [ ] B
 [ ] C

I’ve managed to get a row to the top.
But how do I move a row again to the old position?

example with working code for moving to top:

http://jsfiddle.net/6F5mQ/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:08:40+00:00Added an answer on May 31, 2026 at 11:08 am

    I would store each tr’s position and move it back if/when needed.

    I updated the code according to ShadowScripter’s comment

    http://jsfiddle.net/gguNM/1/

    New update
    http://jsfiddle.net/gguNM/2/

    $('table tr').each(function () {
      var $this  = $(this).data({position: $(this).index()}),
          $table = $this.closest('table'),
          $input = $this.find('input');
    
      $input.bind('click', function (e) {
        var $first = $table.find('tr:first'),
            position;
    
        if ($(this).is(':checked')) {
          position = $first.data('position');
          $table.find('tr input').not($(this)).removeAttr('checked');
    
          if (position != 0) $first.insertAfter($table.find('tr').eq(position));
          $this.prependTo($table);
        } else if ($this.data('position') != 0) {
          position = $this.data('position');
          $this.insertAfter($table.find('tr').eq(position));                
        }
      });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that allows the user to move from a list of
I have the need to return tree like results from a single table. At
I need to move some data from a table to a archive table. Now
I have a table structure as follows. Now I need to sort these nested
My Goal: Is to move data from one table to another if the row
I need to move a huge amount of data from a couple tables in
I need to move data from a datareader into a Farpoint Spreadsheet component in
I need to move backwards through an array, so I have code like this:
I need to move a folder from a plugin to the main app/views. I
I have a need to move an item in an IEnumerable<> up, that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.