Reputation: 3
Primeng - Multiselect
Wanted to move the selected to top in the multiselect dropdown of primeng. How to achieve it?
I Have tried to sort the selected values based on index. that's not working.
items.sort((a:any, b:any) => {
let IndexA = selected.findIndex(((i:any) => i == a[key]));
let IndexB = selected.findIndex(((i:any) => i == b[key]));
return 0;
});
Upvotes: 0
Views: 1774
Reputation: 707
(onChange)="onSelectionChange($event)"
pass $event to catch array of selected elements.onSelectionChange(event:any)
.onSelectionChange(event:any):void {
event?.value.foreach(selectedItem => {
this.items.splice(this.items.indexOf(selectedItem),1) // remove the item from list
this.items.unshift(selectedItem)// this will add selected item on the top
})
}
Upvotes: 2