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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:12:32+00:00 2026-05-28T06:12:32+00:00

Ok just got assigned to a new project and have never dealt with Javascript

  • 0

Ok just got assigned to a new project and have never dealt with Javascript before. Right now the data is moved up and down the grid with the code below. I need to add to the case statement a “top” and “bottom” that will the user the move the selected row to either the top of the grid or the bottom. I am trying to google search answers but not having much luck. Any advice on where I could continue my search would be helpful.

Ok new issue. I added some code that I created. It is in the case statement under “top” and “bottom” The code I added allows me to select an item and move it to the very top of the list. But moving it to the bottom and IE tells me that the script is taking to long. ANy Advice?

Never mind I got the code working. Below is the working code.

function move(direction) {
try {
    if (CSAdmin.selectedItem.element &&
CSAdmin.selectedItem.ID) {
        var row = CSAdmin.selectedItem.element;
        var node =
    getNode(CSAdmin.selectedItem.type, CSAdmin.selectedItem.ID);
        if (node) {
            var sibling = null;
            var rowSibling = null;
            var parent = node.parentNode;
            var rowParent = row.parentNode;
            switch (direction) {
                case "up":
                    {
                        sibling = node.previousSibling;
                        if (sibling) {
                            parent.removeChild(node);
                            parent.insertBefore(node, sibling);
                        }
                        //Move the table row 
                        rowSibling = row.previousSibling;
                        if (rowSibling) {
                            rowParent.removeChild(row);
                            rowParent.insertBefore(row, rowSibling);
                        }
                        break;
                    }
                case "down":
                    {
                        sibling = node.nextSibling;
                        if (sibling) {
                            parent.removeChild(sibling);
                            parent.insertBefore(sibling, node);
                        }
                        //Move the table row if it isn't the insert row
                        rowSibling = row.nextSibling;
                        if (rowSibling && rowSibling.id.indexOf("new", 0) == -1) {
                            rowParent.removeChild(rowSibling);
                            rowParent.insertBefore(rowSibling, row);
                        }
                        break;
                    }
                    case "top":
                    {
                        sibling = node.previousSibling;
                        while (sibling) {
                            if (sibling) {
                                parent.removeChild(node);
                                parent.insertBefore(node, sibling);
                                sibling = node.previousSibling;
                            }
                        }
                        //Move the table row 
                        rowSibling = row.previousSibling;
                        while (rowSibling) {
                            if (rowSibling) {
                                rowParent.removeChild(row);
                                rowParent.insertBefore(row, rowSibling);
                                rowSibling = row.previousSibling;
                            }
                        }
                        break;
                    }
                case "bottom":
                    {
                        sibling = node.nextSibling;
                        while (sibling) {
                            if (sibling) {
                                parent.removeChild(sibling);
                                parent.insertBefore(sibling, node);
                                sibling = node.nextSibling;
                            }
                        }
                        //Move the table row if it isn't the insert row
                        rowSibling = row.nextSibling;
                        while (rowSibling && rowSibling.id.indexOf("new", 0) == -1) {
                            if (rowSibling && rowSibling.id.indexOf("new", 0) == -1) {
                                rowParent.removeChild(rowSibling);
                                rowParent.insertBefore(rowSibling, row);
                                rowSibling = row.nextSibling;
                            }
                        }
                        break;
                    }
            }
        }
    }
}
catch (err) {
    throw new Error("Error moving row:" + err.description);
}
  • 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-28T06:12:33+00:00Added an answer on May 28, 2026 at 6:12 am

    The variable names in your existing code are kind of confusing (you don’t even tell us what node is), but this is the basic premise for making it work. I used jQuery to shortcut the work in this example, but the logic is sound and is not reliant on jQuery.

    http://jsfiddle.net/qukDJ/

    //move to top
    var currentRow = $(this).closest('tr')[0];     
    var firstRow = currentRow.parentNode.childNodes[0];
    currentRow.parentNode.insertBefore(currentRow, firstRow);
    

    Moving to the bottom is basically the same thing except you want lastRow and insertAfter.

    var lastRow = currentRow.parentNode.childNodes[currentRow.parentNode.childNodes.length - 1];
    currentRow.parentNode.insertAfter(currentRow, lastRow);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I just got assigned a project to develop a web application/site that uses
I just got Delphi 2009 and have previously read some articles about modifications that
I just got a shiny, brand-new Debian server handed to me by our Systems
I have got a problem with my codeigniter library. To transform database data into
Strange programming problems as of now..As you can see below i have assigned intFrontPtr
I realize these questions have been asked before on Stackoverflow, but now that FBML
I've got a situation where I have a project with several models that have
I just got stuck. I have 2 view controllers one is WatchListViewController and 2nd
Just got a request from my boss for an application I'm working on. Basically
Just got a question about generics, why doesn't this compile when using a generic

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.