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

Sortable replaces item in new collection instead of inserting it #6539

Open
DmytrievA opened this issue Dec 20, 2022 · 1 comment
Open

Sortable replaces item in new collection instead of inserting it #6539

DmytrievA opened this issue Dec 20, 2022 · 1 comment

Comments

@DmytrievA
Copy link

DmytrievA commented Dec 20, 2022

So I have pagination on my page with bs-sortable component
When I drag item over page number page is switched and new collection is loaded to ngModel binded property
Then I try to drop this item back in bs-sortable (so just move it between pages) but instead of inserting this item in new collection it`s replaces existing one

Plunker/StackBlitz that reproduces the issue:

https://stackblitz.com/edit/ngx-bootstrap-tqauje?file=app/app.component.html

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 5.6.2

Angular: Angular CLI: 7.0.5

Bootstrap: 4.1.1

Expected behavior

I Expect that new item will be added to collection just like in this demo:
https://valor-software.com/ngx-bootstrap/#/components/sortable#basic

Additional issue

On components page mentioned that original collection isn`t mutated and new collection is sended in onChange ad ngModelChange events, but in my project original collection is defenetly changed. Is it bedouse of me using old version or this is known issue?

@DmytrievA
Copy link
Author

for now I've overcomed this problem by creating new collection with all items, including droped one, and assigning this collection to items of bs-sortable:

let items:any[] = [1,2,3,4,5];//bs-sortable binded to this collection
let items_copy:any[] = [];

ngOnInit() {
  this.items_copy = this.items.slice();
}

//this function is called on bs-sortable onChange event
onDrop(event:any[]) {
  let added = event.find(x=>this,items_copy.includes(x)== false);
  if(added) {//item was droped from another page
   let index = event.indexOf(added);                         //getting index of item that was replaced by new one
   this.items_copy.splice(index+1,0,this.items_copy[index]); //inserting old item on it's place
   this.items = this.items_copy.slice();
  }
}

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

1 participant