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

Get newIndex during onMove #1323

Closed
schwamic opened this issue May 17, 2018 · 7 comments
Closed

Get newIndex during onMove #1323

schwamic opened this issue May 17, 2018 · 7 comments
Labels
enhancement Quality of life changes to existing features

Comments

@schwamic
Copy link

schwamic commented May 17, 2018

In the current version there is no easy way to get the current order of the list during onMove. Neither the 'ghost'-element nor an exact position of the 'drag'-element can be identified. However, there must be an exact order within Sortable, why is this information not accessible? It would be a nice feature for a better UX, if the index of the list-items would be updated during onMove instead of onEnd.

I have already tested the following:

  • Sortable.utils.index(evt.related, '.draggable')
  • onMove: evt.dragged or evt.related
  • sortable.toArray()

The index returned is not consistent and therefore cannot be used easily. Often the index by one or two positions does not match the current list. Also the 'toArray' does not give any clear information about the current order of the elements while onMove, and is difficult to find out how the indexes have to be mapped.

Is there currently still another way to get the current order during onMove?

@bhavin36
Copy link

bhavin36 commented Aug 4, 2018

@schwamic If I understand you problem correctly you want to show the current index onMove. Check out this.
You can use CSS counters to show the current index...
Hope this helps.

@antoine-nedelec
Copy link

Yep, I do have the same thing going on here. I use SortableJs to sort a list of canvas elements (1 element is up to the front, 2nd behind, etc...).

When I drag element on my list i'd like to have the instant update/change on my canvas but I currently have to wait until "onUpdate", "onSort", or "onEnd" to trigger. There is still no way to fetch the current order with the "onMove" event ?

@owen-m1
Copy link
Member

owen-m1 commented Jan 11, 2019

@antoine-nedelec Hang tight and it will be in the next version. If you really need it now, you can use Sortable.utils.index(element, '>*');

@antoine-nedelec
Copy link

Thanks that would be great :), but I couldn't find a way to use:
Sortable.utils.index(element, '>*');
In my code.

Would you have a working example with this ?

@owen-m1
Copy link
Member

owen-m1 commented Jan 14, 2019

@antoine-nedelec Use it in the onMove function to get the index in real time

@owen-m1
Copy link
Member

owen-m1 commented Jan 15, 2019

@antoine-nedelec 1.8.0 is published.
As of 1.8.0, use the onChange event.

@owen-m1 owen-m1 closed this as completed Jan 15, 2019
@antoine-nedelec
Copy link

Awesome it works perfectly, thanks. If anyone needs it, the sorted list is under "evt.target.childNodes"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Quality of life changes to existing features
Projects
None yet
Development

No branches or pull requests

4 participants