question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wrong index for old/newIndex in react mixin

See original GitHub issue

For some reason, when sorting items I have 1-based indexes which messes things up when it comes to run items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]);

I’ve had to set this thus:

oldIndex = evt.oldIndex - 1,
newIndex = evt.newIndex - 1

Once I do that, things run fine. Could this be caused by having an element which is not sortable within the same div?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
owen-m1commented, Apr 8, 2019

@cmoutafidis @Backoo You can now use event.newDraggableIndex to get the index of the element only counting draggable elements.

1reaction
Backoocommented, Apr 6, 2019

@cmoutafidis This is not true, but the indexing is more lenient to include non-draggable items. You will have to compensate for any elements in the element you passed into Sortable that are not draggable.

So, Sortable will include non-draggable items when returning indexes. Should this be documented somewhere?

Read more comments on GitHub >

github_iconTop Results From Across the Web

wrong index for old/newIndex in react mixin #494 - GitHub
For some reason, when sorting items I have 1-based indexes which messes things up when it comes to run items.splice(newIndex, 0, ...
Read more >
error: Do not use Array index in keys - Stack Overflow
When you use index of an array as a key, React will optimize and not render as expected. What happens in such a...
Read more >
Sass: @import
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining ......
Read more >
Documentation - Indexed Access Types - TypeScript
The indexing type is itself a type, so we can use unions, keyof , or other ... You'll even see an error if...
Read more >
Indexed Database API 3.0 - W3C
An index has a multiEntry flag . This flag affects how the index behaves when the result of evaluating the index's key path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found