Hello,
I am wondering if there is a way to move items to the top of the dropdown list when they are selected.
This way, if a user selects many things but needs to unselect one item, they don't have to go searching for that item again just to uncheck.
(The dropdown has thousands of items)
Any help is appreciated! Thank you! =)
MultiSelect dropdown selected values at top?
-
- Posts: 1
- Joined: 21 Aug 2020, 14:27
Maybe solved but for others wanting to do the same, I think this will do the trick.
Usage:
Code: Select all
sortArrayBySelected(items: any = [], selected: any = [], compareKey: string)
{
items.sort((a, b) => {
let findAIndex = selected.findIndex((i => i[compareKey] == a[compareKey]));
let findBIndex = selected.findIndex((i => i[compareKey] == b[compareKey]));
if(findAIndex > -1 && findBIndex == -1)
return -1;
else if(findAIndex == -1 && findBIndex > -1)
return 1;
return 0;
});
return items;
}
Code: Select all
sortArrayBySelected(categories, selectedCategories, 'categoryID');
-
- Information
-
Who is online
Users browsing this forum: No registered users and 20 guests