How to prevent multiple selection in jQuery UI Selectable plugin

前端 未结 10 1849
走了就别回头了
走了就别回头了 2020-12-30 00:13

I am using jQuery UI Selectable plugin. I want to select one item at a time. But jQuery UI Selectable plugin allows multiple selection by clicking/ dragging / holding CTRL

10条回答
  •  庸人自扰
    2020-12-30 00:28

    If you want to disable non consecutive multiselection but still wish to keep the dragging selection you can do this.

             stop: function( event, ui ) {
                    if( $(".ui-selected, .ui-selecting").length > 1){
                        var elems = $('.ui-selected, .ui-selecting');
    
                        for(var i = 0; i < elems.length - 1; i++){
                            if($(elems[i]).closest('td').next('td').text() != $(elems[i+1]).text()){
                               //Non consecutive selection detected
                            }
                        }
                    }
                }
    

    It essentially checks if all elements are next to each other.

提交回复
热议问题