angular-ui/ui-sortable

orderBy filter causes wrong item to be dragged

bkuhl opened this issue · 6 comments

Using orderBy such as player in players | orderBy: 'first_name' causes the wrong item to be dragged between two lists. It appears the ui-sortable list is based off of index, prior to sorting.

I started to create a plunker example outside of my project, but it's not quite working, so it's not very useful. I'm experiencing this issue when 2 or more lists are connected and list items are dragged between the two.

plunker: http://plnkr.co/edit/PQlIbjTU5j6IU7uMC0yI?p=preview

It appears to be an issue with ui.sortable indexing items prior to orderBy processing.

How interesting. Up to this point we haven't supported orderBy because we looked at from the perspective of a single list. In that case sortable would have no idea how to change the item to reorder them. In your example, what should it do, change the first letter of the two names, swap the names?

However, I never though about using sortable not to reorder items, but simply to drag them between lists. In which case, orderBy makes sense again.

Now the question becomes whether this should be supported by ui-sortable, or a new, much simpler library.

Essentially all I'm trying to do is drag items between lists, but also
maintain a specific order in the process.

For example, my objective is for both lists to maintain an order by the
player's grade. So if I drag a 7th grader to the top of a list where there
is a 10th grader, it sorts the players correctly as:

  • 10th grader
  • 7th grader
  • 6th grader

On Tue, Dec 3, 2013 at 5:46 PM, CyborgMaster notifications@github.comwrote:

How interesting. Up to this point we haven't supported orderBy because we
looked at from the perspective of a single list. In that case sortable
would have no idea how to change the item to reorder them. In your example,
what should it do, change the first letter of the two names, swap the
names?

However, I never though about using sortable not to reorder items, but
simply to drag them between lists. In which case, orderBy makes sense
again.

Now the question becomes whether this should be supported by ui-sortable,
or a new, much simpler library.


Reply to this email directly or view it on GitHubhttps://github.com//issues/70#issuecomment-29759758
.

Ben Kuhl

Yeah, that makes a lot of sense. Sounds like a perfect use case to me. I don't have time to look at this right now, but hopefully within the next week or two I will. If you want, you can start on a pull-request yourself.

If I get the chance to, I will.

On Tue, Dec 3, 2013 at 5:51 PM, CyborgMaster notifications@github.comwrote:

Yeah, that makes a lot of sense. Sounds like a perfect use case to me. I
don't have time to look at this right now, but hopefully within the next
week or two I will. If you want, you can start on a pull-request yourself.


Reply to this email directly or view it on GitHubhttps://github.com//issues/70#issuecomment-29760170
.

Ben Kuhl

@bkuhl Here is an edited version of your plunk. Please verify that this works as intended, since I didn't have much time.

As already descussed in other issues

ui-sortable's model should match the ng-repeater's model

Always prefer applying filters in the controller instead of the 'view'.
This is:

Please reopen if applicable.

Yep, that's the functionality I was looking for... thanks!!