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:


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



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



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:


            simpleDesc : desc,

            list: []


            priority: -1



Then, in my sorted parameters, I:

$scope.sortableOptions = {
    stop: function(event, ui) {
            todo.priority = $scope.todos.indexOf(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' " > .....




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 .



All Articles