angular-sortable-view
angular-sortable-view copied to clipboard
Elements don't stay in new position
Hello, thank you for the awesome module @kamilkp !! I have an issue, and I don't know if i'm just being stupid or if it is an actual issue: elements I move by drag and dropping do not stay on the new position, but rather go back to their previous position... I can confirm using "sv-on-sort" that both the $indexFrom and $indexTo are correct. Here's my code:
<div class="row sortable-container" sv-root sv-part="stories" sv-on-sort="doAlert($indexFrom, $indexTo);">
<div ng-repeat="post in stories | selectedStories:activeStories" sv-element class="col maincol center well" style="width: {{columnWidth}}%">
<h5 class="no-margin story-title">{{post.title}}</h5>
</div>
</div>
EDIT: I think this may be due to the filter I'm applying? Been beating my head for a few hours, any help would be appreciated... Here's the custom filter:
.filter('selectedStories', function() {
return function(stories, activeStories) {
return stories.filter(function(story) {
if (activeStories.indexOf(story.$id) != -1) {
return true;
}
return false;
});
};
})
And activeStories
is just an array where I put the id's of the stories I want to show.
EDIT2: After running various tests it appears the problem is that this doesn't work when the ng-repeat is iterating over a filtered array. Can anyone confirm? Any workarounds?
@CharlieIGG I ran into this issue as well. You are correct that it doesn't work when the ng-repeat is iterating over a filtered array. This is because the model for the sorting and the ng-repeat are different.
A workaround would be to order the array before it is applied to the ng-repeat rather than using an orderBy filter.
Change
<div ng-repeat="post in stories | selectedStories:activeStories">
To
<div ng-repeat="post in activeStories">
activeStories being the ordered array
just saw this... Thanks @mcestone4 !