Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda