How to have only one direction jquery sortable items between lists?

Is their way to include one direction of data where one table1 can only give elements and table2 can only take elements?

 $(function() { $( "#sortable1, #sortable2" ).sortable({ connectWith: ".connectedSortable" }).disableSelection(); }); 

Please forgive my inexperience, any information will be appreciated.

+4
source share
1 answer

From the API Docs :

connectWith: Selector of other sortable elements to which elements from this list should be connected. This is a one-way relationship , if you want the elements to be connected in both directions, the connectWith option should be set on both elements to be sorted .

The sample code you gave seems to be similar to the jQuery UI demo site below. If you study the code, you will notice that the CSS class .connectedSortable declared in both lists:

 <ul id="sortable1" class="connectedSortable"> <li class="ui-state-default">Item 1</li> ... </ul> <ul id="sortable2" class="connectedSortable"> <li class="ui-state-highlight">Item 1</li> ... </ul> 

The code you provide will make this sortable list bidirectional. To do this unilaterally, you can specify a different selector:

 $(function() { $( "#sortable1, #sortable2" ).sortable({ connectWith: "#sortable2" // changed this to reflect the ID of the second list }).disableSelection(); }); 

See jsFiddle for example

+5
source

Source: https://habr.com/ru/post/1500842/


All Articles