angular-ui / ui-sortable

jQuery UI Sortable for AngularJS
http://angular-ui.github.io/ui-sortable/
MIT License
1.26k stars 444 forks source link

Is it possible to give the output of serialize or toArray back to the ui-sortable component and have it reorder at runtime? #537

Closed digitalpowers closed 6 years ago

digitalpowers commented 6 years ago

I saved my sorted list of objects (to a database but probably not important) by using toArray but now I want to restore the order when I come back to the page later. However while I can get the array out of the database when the controller starts I cant figure out how to reorder the list.

Note: the list provided by the controller is made of complex objects not just a list of id's. They load from a rest interface. What I would love is to be able to provide the preferred order back to the ui-sortable but if any objects don't exist or new objects do exist it would handle it gracefully.

I feel like i might just be barking up the waaay wrong tree but to be fair I am not really a UI guy so it might not be surprising.

thgreasi commented 6 years ago

Can't you just assign your restored array to your ngModel scope variable?

digitalpowers commented 6 years ago

I am hoping I just dont understand but the serialized list is just the id's of the actual model that is being serialzied. So I cant just assign that list of id's to the model right?

thgreasi commented 6 years ago

Can you share a sample object for your ngModel and the serialized array? I guess that this is not so much related to ui-sortable and more of a "how to program this" question. Forking one of the codepen examples found in README would be ideal.

digitalpowers commented 6 years ago

Perhaps you were right, I ended up using the ordered array to sort the backing object after it was loaded, originally I didnt think that worked because the sort order didnt visibly change, i had to trigger a digest or whatever. I am definately a noob in this area sorry :)

thgreasi commented 6 years ago

I'm glad you found your way around 👍