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

fix: default indexes replaced in onAdd and onDelete events #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions projects/ngx-sortablejs/src/lib/sortablejs.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,19 @@ export class SortablejsDirective implements OnInit, OnChanges, OnDestroy {
return {
onAdd: (event: SortableEvent) => {
this.service.transfer = (items: any[]) => {
this.getBindings().injectIntoEvery(event.newIndex, items);
const indexes = getIndexesFromEvent(event);
this.getBindings().injectIntoEvery(indexes.new, items);
this.proxyEvent('onAdd', event);
};

this.proxyEvent('onAddOriginal', event);
},
onRemove: (event: SortableEvent) => {
const bindings = this.getBindings();

const indexes = getIndexesFromEvent(event);
if (bindings.provided) {
if (this.isCloning) {
this.service.transfer(bindings.getFromEvery(event.oldIndex).map(item => this.clone(item)));
this.service.transfer(bindings.getFromEvery(indexes.old).map(item => this.clone(item)));

// great thanks to https://github.com/tauu
// event.item is the original item from the source list which is moved to the target list
Expand All @@ -167,7 +168,7 @@ export class SortablejsDirective implements OnInit, OnChanges, OnDestroy {
this.renderer.insertBefore(event.clone.parentNode, event.item, event.clone);
this.renderer.removeChild(event.clone.parentNode, event.clone);
} else {
this.service.transfer(bindings.extractFromEvery(event.oldIndex));
this.service.transfer(bindings.extractFromEvery(indexes.old));
}

this.service.transfer = null;
Expand Down