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 6837701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:30:31+00:00 2026-05-26T23:30:31+00:00

I have a table with an HTML attribute on the TR element titled data-order

  • 0

I have a table with an HTML attribute on the TR element titled “data-order” which simply holds an integer indicating the order in which to sort the table (descending). Right now the code only checks the row ahead of the TR clicked – what I’m attempting to do is to get it to scan all rows ahead of its position in the table and once it finds a number greater than (not greater than or equal to) then call the swaprow function…

Here is the javascript used to move the row up.

function adjustRank(id, e) {
    var url = "/ajax/moveup/" +  aid;
    var row = $(e).closest("tr").get(0);
    var prevRow = $(row).prev().get(0);
    var moveUp = false;
    var prevRowOrder = parseInt($(prevRow).attr("data-order"));
    var rowOrder = parseInt($(row).attr("data-order"));

    $.ajax({
        type: "POST",  
        url: url,
        data: {aid: aid},
        dataType: "json",
        success: function () 
        { 
            if(rowOrder + 1 > prevRowOrder)  // think this is where I need to traverse the table
                swapRows(row, prevRow);
        },
        failure: function () { alert("Error processing request."); }
    });
}

and here are a couple of items in the table for example:

<table id="listings" style="min-height:150px; width:100%;">
    <tr id="1" data-order="11"><td>1</td><td align="left"><span onclick="adjustRank('ace93485-cea5-4243-8294-9f3d009aba3d', this)" style="cursor:pointer;">Lindsey Vonn</span></td><td></td></tr>
    <tr id="2" data-order="6"><td>2</td><td align="left"><span onclick="adjustRank('9f83aed6-b99a-4674-a8b7-9f3d009aba38', this)" style="cursor:pointer;">Al Horford</span></td><td></td></tr>
    <tr id="3" data-order="5"><td>3</td><td align="left"><span onclick="adjustRank('d48a52bd-17e9-4631-9a2e-9f3d009aba39', this)" style="cursor:pointer;">Derek Jeter</span></td><td></td></tr>
</table>
  • 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-26T23:30:32+00:00Added an answer on May 26, 2026 at 11:30 pm

    You may use recursion to solve that problem. Please, see the code.

    window.adjustRank = function(id, el) {
        var orderDiff = 1; 
        var row = $(el).closest("tr");
        var order = parseInt(row.attr("data-order")) + orderDiff;
        row.attr("data-order", order);
    
        var prevRow = row.prev();
        if(prevRow.get(0)){
            moveUp(order, row, prevRow);
        }
    }
    
    window.moveUp = function(order, row, prevRow){
        if(order > parseInt(prevRow.attr("data-order"))){
            var prevPrevRow = prevRow.prev();
            if(prevPrevRow.get(0)){
                moveUp(order, row, prevPrevRow);
            } else {
                prevRow.before(row);
            }
        } else {
            prevRow.after(row);
        }
    }
    

    If you get orderDiff via AJAX, then place the code into your AJAX call success function. Please, see this demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an html table which i bind data dynamically on the server side
I have an HTML table in which each data row has a unique id
I have an HTML table, where each cell contains a large amount of data.
if in html table have 5 row, 1 and 2 are safe, 3,4,5 must
how remove html table rows after 2nd row? if in table have 5 row,
I have an html table <table border=0 width=100%> <tr class=headerbg> <th width=5%> No </th>
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2
I have an HTML table with several columns and I need to implement a
I have a HTML table like this: <table border=1> <tbody> <tr> <td><a href=# class=delete>DELETE
I have a HTML table like this: <table border=1> <tbody> <tr> <td><a href=# class=delete>DELETE

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.