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

  • Home
  • SEARCH
  • 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 6574561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:16:36+00:00 2026-05-25T15:16:36+00:00

By default, while sorting, items are replaced (for example, if I take the third

  • 0

By default, while sorting, items are replaced (for example, if I take the third element and move it to the first, than the first and the second elements will move down)

I do not need this behaviour. I’d like elements not to change order while I finish sorting (release mouse).

I need this because I want to ask user if he want to change element or to re-order?

P.S. option tolerance have only 2 options, and they don’t help in this situation.

  • 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-25T15:16:36+00:00Added an answer on May 25, 2026 at 3:16 pm

    I meant something like this (sortable list with option of replacing elements):

    $(function() {
    
      var
    
        /**
         * Sortable List, that can insert or replace elements
         */
        SortableList = (function() {
    
          var
    
            // Configuration of Sortable list
            // css classes of separator and sortable elements
            // jQuery UI droppable and sortable init configuration
            CONFIG = {
    
              'confirm-message': 'Insert? Element will be removed',
    
              'separator-class': 'sortable-separator',
              'sortable-class': 'sortable-elem',
    
              // Initialization of jQuery UI Droppable
              'separators-droppable-init': {
                drop: function(e, ui) {
                  // Insertation
                  var drag = ui.draggable,
                    drop = $(this),
                    a = drop.prev(),
                    b = drop.next();
    
                  Separators.clean();
                  Elements.insert(a, b, drag);
                  Separators.init();
                },
                over: function(e, ui) {
                  $(this).css({
                    'background-color': 'lightgreen'
                  });
                },
                out: function(e, ui) {
                  $(this).css({
                    'background-color': 'white'
                  });
                }
              },
    
              'sortable-droppable-init': {
                drop: function(e, ui) {
                  // Replace
                  var drag = ui.draggable,
                    drop = $(this);
    
                  if (Elements.replace(drop, drag)) {
                    Separators.init();
                  }
                }
              },
              'sortable-draggable-init': {
                revert: true,
                start: function(e, ui) {
                  $(this).css({
                    'z-index': '999',
                    'cursor': 'move'
                  });
                },
                stop: function(e, ui) {
                  $(this).css({
                    'z-index': '1',
                    'cursor': 'default'
                  });
                }
              }
            },
    
            getSeparators = function() {
              return $('.' + CONFIG['separator-class']);
            },
    
            getSortables = function() {
              return $('.' + CONFIG['sortable-class']);
            },
    
            /**
             * Separators Handler
             */
            Separators = (function() {
    
              var
                // create separator html element
                _create = function() {
                  return $('<div />').addClass(CONFIG['separator-class']);
                },
    
                // create all separators and insert them
                createAll = function() {
                  getSortables().each(function() {
                    $(this).before(_create());
                  }).last().after(_create());
                  return Separators;
                },
    
                // remove all separators
                clean = function() {
                  var s = getSeparators();
                  if (s.length) {
                    s.remove();
                  }
                  return Separators;
                },
    
                // init jQuery UI Droppable interface
                initDroppable = function() {
                  getSeparators().droppable(CONFIG['separators-droppable-init']);
                  return Separators;
                },
    
                // Initialization of separators
                init = function() {
                  if (getSeparators().length) {
                    Separators.clean();
                  }
                  return Separators.createAll().initDroppable();
                };
    
              // Return result    
              Separators = {
                clean: clean,
                createAll: createAll,
                init: init,
                initDroppable: initDroppable
              };
    
              return Separators;
            }()),
    
    
            Elements = (function() {
              var
    
                init = function() {
                  getSortables().droppable(CONFIG['sortable-droppable-init']).draggable(CONFIG['sortable-draggable-init']);
                  return Elements;
                },
    
                // replaces element A with element B
                replace = function(A, B) {
    
                  if (!confirm(CONFIG['confirm-message'])) {
                    return false;
                  }
                  B.draggable("option", "revert", false).css({
                    top: 0,
                    left: 0
                  });
                  A.replaceWith(B);
                  return Elements;
                },
    
                // insert element C between elements A and B
                insert = function(A, B, C) {
                  C.draggable("option", "revert", false).css({
                    top: 0,
                    left: 0
                  });
                  if (!A.length) {
                    B.before(C);
                  } else {
                    A.after(C);
                  }
                  return Elements;
                },
    
                // result to return
                Elements = {
                  init: init,
                  replace: replace,
                  insert: insert
                };
    
              return Elements;
    
            }()),
    
            init = function() {
              Separators.init();
              Elements.init();
            };
    
          return {
            init: init
          };
        }());
    
      SortableList.init();
    
    });
    .sortable-elem {
      width: 32px;
      height: 32px;
      background-color: darkred;
      border: 1px solid brown;
      color: white;
    }
    
    .sortable-separator {
      width: 100px;
      height: 16px;
      position: relative;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
    <link href="//code.jquery.com/ui/1.8.16/themes/smoothness/jquery-ui.css" rel="stylesheet" />
    <script src="//code.jquery.com/ui/1.8.16/jquery-ui.min.js"></script>
    
    <div class="sortable-elem" data-order="1">1</div>
    <div class="sortable-elem" data-order="2">2</div>
    <div class="sortable-elem" data-order="3">3</div>
    <div class="sortable-elem" data-order="4">4</div>
    <div class="sortable-elem" data-order="5">5</div>
    <div class="sortable-elem" data-order="6">6</div>
    <div class="sortable-elem" data-order="7">7</div>
    <div class="sortable-elem" data-order="8">8</div>
    <div class="sortable-elem" data-order="9">9</div>
    <div class="sortable-elem" data-order="10">10</div>

    View on JSFiddle

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

Sidebar

Related Questions

I want to create wrapper class, which will enable keys duplicates while default hash
While reading the answers to this question I got a doubt regarding the default
By default it will not print out anything until the whole page has finished
Some native iPhone applications (like Clock) display different default images while loading depending on
Im running a web application in visual studio 2008... while running, my first web
How can I show some default input while there is no user input? I
My php file located at port 80 (default port) while my ajax call are
The default color of the UITabBarController is black while the default color of the
I am facing a strange problem while sorting a list of strings with integer
While debugging some code, I came across an array named default . I thought

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.