ui-sortable icon indicating copy to clipboard operation
ui-sortable copied to clipboard

Cannot get it to save first sort, all other sorts save just fine.

Open DISRUPTIVE-INC opened this issue 11 years ago • 1 comments

I'm using ui-sortable with firebase/angularfire to save the data. Here's my setup:

//set options for ui-sortable
    $scope.sortableOptions = {
        stop: function(event, ui) {
            $scope.userList.forEach(function(todo){
             todo.sort = $scope.userList.indexOf(todo);
              $scope.userList.$save(todo);
            });
      },
      axis: 'y'
    }

<ul ui-sortable="sortableOptions" ng-model="userList">
<li ng-repeat = "task in userList | orderBy: 'sort'"> 
</li>
</ul>

When I try to sort the first time, everything will move back to its original position. If I try to sort again after that everything works great. Any ideas?

DISRUPTIVE-INC avatar May 09 '15 23:05 DISRUPTIVE-INC

You should not apply filters to ng-repeat since (as README states):

...Otherwise the index matching of the generated DOM elements and the ng-model's items will break. In other words: The items of ng-model must match the indexes of the generated DOM elements.

Filtering/Ordering should (ng filters in general that manipulate the ng-model) be applied in the controller and not in the view. For more details read the comments in #70

Please refer to the filtering and two ordering examples found in README on how you should properly apply your logic inside the controller.

thgreasi avatar May 10 '15 08:05 thgreasi