Disable the Sort option

How can I temporarily disable sorting using javascript from https://github.com/RubaXa/Sortable ?

see this jsfiddle example . what it is configured:

$('ul').each(function( index ) {new Sortable(this, { group: "sortgroup" });
             }); 
+4
source share
3 answers

The dev version , which will be released in December 2014, presents an option sort: <Boolean>. Setting it to falsedisable the ability to sort the list. This is useful if you want to have a "source" list from which you can drag and drop items to the "target" list, but don’t want to sort the items in the source list.

- http://rubaxa.imtqy.com/Sortable/#ag

: http://jsbin.com/sevofa/1/edit?html,js,output

var sortable = new Sortable(document.getElementsByClassName('sortable')[0], {
      group: 'foo',
      sort: false,
      animation: 150
});

switcher.onchange = function () {
  var on = switcher.sort.value == 1;
  sortable.option('sort', on);
};
<script src="https://rawgit.com/RubaXa/Sortable/dev/Sortable.js"></script>

<form id="switcher">
  sort: 
  <label><input checked name="sort" value="0" type="radio"/> false</label>  
  <label><input name="sort" value="1" type="radio"/> true</label>
</form>

<ul class="list-group sortable">
  <li class="list-group-item">This is <a href="http://rubaxa.imtqy.com/Sortable/">Sortable</a></li>
  <li class="list-group-item">It works with Bootstrap...</li>
  <li class="list-group-item">...out of the box.</li>
  <li class="list-group-item">It has support for touch devices.</li>
  <li class="list-group-item">Just drag some elements around.</li>
</ul>
Hide result
+1

-.

$('ul').each(function( index ) {
    new Sortable(this, { group: "sortgroup", handle: ".someClass"});
}); 

, . .

+1

This is the use of html5 draggable attr. You can just turn it off.

$('#items li').attr('draggable', 'false')
-1
source

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


All Articles