angularjs - How to sort list using Angular Sortable and Rails -


i'm stuck problem. i;ve built api in rails , client in angular. i've got model called todo has property called order. when create new todo, automatically assign newly created todo value order so:

@todo = todo.create(todo_params) @todo.order = todo.count + 1 

and display todos:

@todos = todo.where(...).order(:order.desc) 

in client i'm using sortable ui manipulation , there's method called onupdate gives me new indexes array.

the problem i'm having indexes considerably different value i've in order property. when aforementioned function called item , 2 more values: newindex , oldindex, problem doesn't give me index of other todos, how can reorganise on database?

i'd appreciate i'm bit @ loss here.

ps: please note rails api only, no views.

edit

output wanted:

let's imagine this: have 3 items in database: {name: a, order: 1}, {name: b, order: 2}, {name: c, order: 3}. in front-end, while using ng-repeat, each item have $index. let's argument sake have $index value of 0, b 1, c 2. @ moment, when use angular library sortable, when manually sort list, values: oldindex , newindex corresponds position of item i've moved within array, not shows position of items within array, don't know how use properties these values update object in database.

for might interested: @ end i've used following solution:

every time sortable updated item, sends array items on in correct order. looped through array , updated each item new order. not sure efficient way resolved problem now.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -