Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
SortableJS lists and fixed/locked items

I need to create an orderable drag and drop list where one or more positions can be fixed as well as the link model:

http://jsfiddle.net/euo4tfcz/

var locktos = [];
$(document).ready(function() {
    $("#sortable li.static").each(function () {
      locktos.push($(this).index());
        $(this).attr("id", "static-" + $(this).index());
    }); 
    alert($("#sortable li").eq(locktos[1]).attr("id"));
});
$("#sortable").sortable({
    "cancel":"li.static",
    "change":function(event,ui) {
       // var locktos = [1, 5];
       for(i=0;i<locktos.length;i++) {
           console.log(locktos[i]);
            var thisindex = $(ui.helper).index();         
            var fixed = $("#static-"+locktos[i]);           
            var index = fixed.index();
            var targetindex = locktos[i]+1;
           console.log(index + ", targetindex: " + targetindex);
            if(index !== targetindex) {         
                if(index > targetindex ) {
                    fixed.prev().insertAfter(fixed); //move it up by one position
                } else if(index==(targetindex-1) && thisindex>targetindex) {
                    //don't move it at all
                } else {
                    fixed.next().insertBefore(fixed); //move it down by one position
                }
            } else if(index==targetindex && thisindex>targetindex) {
                fixed.prev().insertAfter(fixed); //move it up by one position
            }  
           
    }
    }
});
ul > li {display:block;height:15px;width:100px;background:#ccc;margin:2px;padding:3px;border:1px solid #aaa;}
<ul id="sortable">
    
    <li>oranges</li>
    <li class="static">apples</li>
    <li>bananas</li>
    <li>pineapples</li>
    <li>grapes</li>
    <li class="static">pears</li>
    <li>mango</li>
</ul>

But I need to do this with the SortableJS plugin from this link below http://sortablejs.github.io/Sortable/

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!