Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements don't stay in new position #94

Open
CharlieIGG opened this issue Jun 5, 2016 · 2 comments
Open

Elements don't stay in new position #94

CharlieIGG opened this issue Jun 5, 2016 · 2 comments

Comments

@CharlieIGG
Copy link

CharlieIGG commented Jun 5, 2016

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?

@mcestone4
Copy link

@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

@CharlieIGG
Copy link
Author

just saw this... Thanks @mcestone4 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants