Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularUI: Correctly updating the models between two lists with a filter applied
    primarykey
    data
    text
    <p>I'm using Sortable within AngularUI to manage multiple sortable lists. I've got it working to the point where I can easily move items between the lists, and update their corresponding models accordingly. However, if I include a query filter I run into a bit of issues if the following takes place:</p> <ol> <li>The user enters a search field for an item that is NOT the first entry of a list.</li> <li>The user moves the first item in the filtered results from one list to another.</li> <li>It seems to work, until the query is cleared and the initial lists are shown. While it seemed that you moved the entry when you had the query applied, you'll notice that after it's cleared the first entry in the unfiltered array was moved instead.</li> </ol> <p>It seems that Sortable doesn't take filters into account when you are dragging and dropping. Here's the relevant HTML:</p> <pre><code> &lt;p&gt;Search: &lt;input ng-model="query" /&gt;&lt;/p&gt; &lt;div class="column-wrapper"&gt; &lt;ul ui-sortable="sortableTemplates" ng-model="list1" id="sortable1" class="connectedSortable"&gt; &lt;li ng-repeat="item in list1|filter:query" class="itemBox"&gt;{{item.name}}&lt;/li&gt; &lt;/ul&gt; &lt;ul ui-sortable="sortableTemplates" ng-model="list2" id="sortable2" class="connectedSortable"&gt; &lt;li ng-repeat="item in list2|filter:query" class="itemBox"&gt;{{item.name}}&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>And the corresponding JS:</p> <pre><code>var app = angular.module('myApp', ['ui.sortable']); app.controller('test', function($scope) { $scope.list1 = [ {name: 'ABC'}, {name: 'DEF'}, {name: 'GHI'} ]; $scope.list2 = [ {name: 'JKL'}, {name: 'MNO'}, {name: 'QRS'} ]; $scope.sortableTemplates = { connectWith: '.connectedSortable' } </code></pre> <p>});</p> <p><a href="http://plnkr.co/edit/1WhMLrBwaxK4t8pnThj3?p=preview" rel="nofollow">Here it is running on Plunker.</a></p> <p>To replicate the problem, you can try doing a search for <code>GHI</code>, then moving <code>GHI</code> to list2. Then, clear the search box. <code>ABC</code> is the one that actually moves to list2 (as it is the first element in that array), and <code>GHI</code> remains in list one.</p> <p>Is there a way to have sortable get along with Angular filters, so that the original index is preserved when sorting between lists?</p> <p>(I'm new to using Angular as well as JQueryUI, so the answer may be glaringly obvious. I found similar questions, but nothing that seemed to directly address this issue.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload