Using angular ui-sortable and angularfire is there a way to keep the new ordering in the database when sorting?

I am trying to use ui-sortable to sort a list and then keep the new order of the list for firebase using angularfire so that it maintains the correct order when updated. Can this be achieved?

Here's the relevant code:

// HTML

<div ui-sortable="sortableOptions" ng-model="andreyTasks">
  <div ng-repeat="task in andreyTasks"></div>
</div>

      

//controller

    $scope.sortableOptions = {
    axis: 'y',
    stop: function( event, ui ) {
      //save the new sort order
    }
  };

      

+3


source to share


2 answers


I hacked something together that works - not very elegant.

So if I have a list of todo (firebaseArray) .. where the add looks like this:

$scope.todos.$add({

            simpleDesc : desc,

            list: []

                ,

            toggle:false,
            optionMenu:false,
            taskCount:0,
            doneCount:0,
            priority: -1

    })

      

Then, in my sorted parameters, I:



$scope.sortableOptions = {
    stop: function(event, ui) {
        $scope.todos.forEach(function(todo){
            todo.priority = $scope.todos.indexOf(todo);
            $scope.todos.$save(todo);
    });
   }
}

      

The corresponding components of the front panel are as follows:

<div class="row" ng-model = "todos" ui-sortable="sortableOptions" >
  <div class="input-group" ng-repeat = "todo in todos |orderBy:  'priority' " > .....

      

+1


source


Just added a ua-sortable example of firebase integration in the ui-sortable README based on the great code example noted in firebase / angularfire # 687 .



0


source







All Articles