Skip to main content

SortableJS ascending descending sort

I use bootstrap and sortable.js, the created table works very well for moving items with the mouse

I want to sort a table with buttons

How do I implement a sort on the buttons that will sort the list by Ascending/Descending ?

// sort: true
Sortable.create(sortTrue, {
  group: "sorting",
  sort: true
});

// sort: false
Sortable.create(sortFalse, {
  group: "sorting",
  sort: false
});
body {
  padding: 20px;
}
#sortTrue{
  margin-top:10px;
}

.list-group-item {
  cursor: move;
  cursor: -webkit-grabbing;
}
 
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
  
  
  <!-- Latest Sortable -->
  <script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"></script>
  
   
  <button>ascending</button>
  <button>descending</button>

  <!-- sort: true -->
  <div id="sortTrue" class="list-group">
    <div class="list-group-item">foo</div>
    <div class="list-group-item">bar</div>
    <div class="list-group-item">baz</div>
  </div>
  
  
  <!-- sort: false -->
  <div id="sortFalse" class="list-group">
    <div class="list-group-item">qux</div>
    <div class="list-group-item">quux</div>
  </div>
Via Active questions tagged javascript - Stack Overflow https://ift.tt/wfRmnUr

Comments