JQuery sortable lists and fixed/locked items

前端 未结 9 1584
故里飘歌
故里飘歌 2020-11-28 06:07

Is it possible to lock list items in JQuery sortable list in a way that those items will stay in that particular place in the list.

For example,

consider th

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 06:39

    I extended the jQuery.Ui.sortable:

    Overview

    jQuery.Ui.sortable widget extension with fixed feature. This feature allows user to fix elements in the list.
    With the .fixedsortable() constructor you construct a .sortable() class which extended with the features. You can use the original methods and the extended as well.

    Code

    https://gist.github.com/3758329#file_fixedsortable.js > fixedsortable.js

    Example

    http://jsfiddle.net/omnosis/jQkdb/

    Usage

    General:

    To use, add the fixed property to the sortable list optios:

    $("#list").fixedsortable({
       fixed: (value)
    })
    

    the value can be:

    • integer example: 3
    • array of integers example : [1,2,5]
    • a html element or a list of html elements
    • a css selector
    • jquery object

    HTML:

     //the jquery 
     //the original jquery-ui   
     //the extended sortable
    ...
    
    • oranges
    • apples
    • bananas
    • pineapples
    • grapes
    • pears
    • mango
    • bananas
    • oranges
    • apples
    • pineapples
    • grapes
    • pears
    • mango
    • bananas
    • oranges
    • apples
    • pineapples
    • grapes
    • pears
    • mango

    Javascript

    $(function() {
        $("#sortable1").fixedsortable({
            fixed: "> .static"
        });
    
        $("#sortable2").fixedsortable({
            fixed: $("li[foo]").css("background","red")
        });
    
        $("#sortable3").fixedsortable({
            fixed: 2
        })
    });
    

    Notes:

    If you insist to use the .sortable instead of .fixedsortable you can use this https://gist.github.com/3758329#file_sortable.js instead of the jquery.ui library. This is a complete replacement of the jQuery.ui, but i don't recommend to use this because of later updates.

    i have been working on this more than 12 hours :( i am insane..

提交回复
热议问题