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

Unexpected sorting method #10

Open
gufoscuro opened this issue Jul 7, 2020 · 3 comments
Open

Unexpected sorting method #10

gufoscuro opened this issue Jul 7, 2020 · 3 comments

Comments

@gufoscuro
Copy link

gufoscuro commented Jul 7, 2020

Hello!
Great component, thanks for your work!

I could be wrong on this, but let me explain my doubt. Let's say I have a list of 3 elements

  • Element 1
  • Element 2
  • Element 3

As soon as I click on Element 1 and I drag it down over Element 3, my expectation is that the Element 1 goes at third position (and that happens) however what usually happens in a sorting list is that Element 3 should shift up to the second position, instead of swapping its position with the first element

To be clear the list after the sort appears this way:

  • Element 3
  • Element 2
  • Element 1

Though I would expect this:

  • Element 2
  • Element 3
  • Element 1

Does this make sense? I guess it could be probably be achieved with #3

thank you! :)

@Gjum
Copy link

Gjum commented Jul 7, 2020

I wanted the same behavior so I took #3 and made it into its own fork: https://github.com/Gjum/svelte-dragdrop-list

@iandoesallthethings
Copy link

@Gjum Using your repo now! It's really nice. I hope your pull request gets accepted soon.

@rudrakpatra
Copy link

rudrakpatra commented Feb 13, 2022

I think its best to make a prop called behaviour that chooses the function based on string "swap"/"sort" or may be a custom function!!
for
behaviour="swap"
1,2,3 to 3,2,1 (click:1, up:3)

    const swapElements=()=>{
        const temp=list[pick];
        list.splice(pick,1,list[replace]);
        list.splice(replace,1,temp);
        list=list;
    }

behaviour="reinsert"
1,2,3 to 2,3,1 (click:1, up:3)

    const reinsertElements=()=>{
        const temp=list[pick];
        list.splice(pick,1);
        list.splice(replace,0,temp);
        list=list;
    }

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

4 participants