dynamically enable/disable jquery sortable item

前端 未结 5 1334
南旧
南旧 2021-02-07 15:31

I have table rows that are sortable depending on whether certain radio buttons are checked or not. The sortables are initialized on document.ready as follows:

5条回答
  •  再見小時候
    2021-02-07 15:51

    I've been trying to do the same thing. I really wanted the items feature rather than disabled. As pointed out above, there is a weakness in the jQueryUI implementation whereby the sortable don't refresh the items list should the items matched by the selectors change.

    To get around this, I simply destroyed and reinstantiated the sortabled. I've adapted Hannele's JSfiddle to demonstrate (http://jsfiddle.net/Sxg8D/140/).

    $("#sorted-list").sortable({
        items:"li:not(.disabled)"
    });
    
    $("#sorted-list input").click(function() {
        if (this.checked) {
            $(this.parentElement).removeClass("disabled");
        } else { 
            $(this.parentElement).addClass("disabled");
        }
    
        $("#sorted-list")
            .sortable( "destroy" )
            .sortable({
                items:"li:not(.disabled)"
            });
    });
    

提交回复
热议问题