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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:01:52+00:00 2026-05-29T11:01:52+00:00

I have a list made as sortable using jQuery UI. The first list item

  • 0

I have a list made as sortable using jQuery UI. The first list item is “Item 1”, second is ‘Item 2” like that. My requirement is the list items must be initialized based on the order stored in the array “arrValuesForOrder“. How do we initialize it so?

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>

<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/sunny/jquery-ui.css"
rel="stylesheet" type="text/css" />

<script type="text/javascript">


    $(document).ready(function () 
    {

        var arrValuesForOrder = ["3", "1", "4", "2"];

        $("#myUnorderedList").sortable({
                                    axis:'y',
                                    handle: '.handle',
                                    update: function () 
                                            {
                                                var order = $('#myUnorderedList').sortable('serialize');
                                                alert(order);
                                            }
        });
    }); 
</script>

<style>

#myUnorderedList li img.handle 
{
margin-right: 20px;
cursor: move;
}

#myUnorderedList li 
{
display: block;
margin-bottom: 3px;
height:30px;
background-color: #efefef;
}

</style>


</head>

<body>

<div>


<ul id="myUnorderedList"> 

  <li id="listItem_1"> 
    <img src="images/arrow.png" alt="move"  class="handle" /> 
    <strong>Item 1</strong> 
  </li> 

  <li id="listItem_2"> 
    <img src="images/arrow.png" alt="move" class="handle" /> 
    <strong>Item 2</strong> 
  </li> 

  <li id="listItem_3"> 
    <img src="images/arrow.png" alt="move"  class="handle" /> 
    <strong>Item 3</strong> 
 </li> 

  <li id="listItem_4"> 
    <img src="images/arrow.png" alt="move" class="handle" /> 
    <strong>Item 4</strong> 
  </li> 

</ul> 


</div>

</body>
</html>
  • 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-29T11:01:53+00:00Added an answer on May 29, 2026 at 11:01 am

    I don’t think the sortable plugin comes with an option to set the initial order of the elements. I think it expects the elements to be initially rendered in the correct order (which makes sense in my opinion – why don’t you do that ?)

    Anyway, here’s a piece of code that will sort the elements prior to initializing the sortable plugin:

    var arrValuesForOrder = ["3", "1", "4", "2"];
    
    var $ul = $("#myUnorderedList"),
        $items = $("#myUnorderedList").children();
    
    // loop backwards so you can just prepend elements in the list
    // instead of trying to place them at a specific position
    for (var i = arrValuesForOrder[arrValuesForOrder.length - 1]; i >= 0; i--) {
        // index is zero-based to you have to remove one from the values in your array
        $ul.prepend( $items.get(arrValuesForOrder[i] - 1));
    }
    
    $("#myUnorderedList").sortable({
        axis: 'y',
        handle: '.handle',
        update: function() {
            var order = $('#myUnorderedList').sortable('serialize');
            alert(order);
        }
    });
    

    DEMO

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

Sidebar

Related Questions

I have a table that I've made sortable using the jQuery plugin Tablesorter 2.0
I have a page using jQuery with some lists which have been made sortable.
I have a sortable list using JQueryUI and use the JQuery Each function to
I have made a page in which i m using a list to display
Hey, I right now have a list of a struct that I made, I
I have a list box with items like A B C D E .
I have made a sortable list. Based on the order of the sortable list
I have a list of strings made of 1.9-2 MILLION items . The following
I have two tabs: In first tab I have a fixed list of items.
I have a list that I would like to sort in multiple ways. My

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.