primefaces / primefaces/primeng
PrimeNG p-multiSelect: Keep Selected Items on Top
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.5k
- Forks
- 5.1k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using PrimeNG's p-multiSelect component with multiple selection enabled. Every time I select an item, I don't want to search for it again in the list. Instead, I want the selected items to always appear at the top of the dropdown.
Current Behavior:
When I select multiple items, they stay in their original position in the list.
If the list is long, I have to scroll or search again to find my selected items.
Expected Behavior:
Selected items should automatically move to the top of the list.
The remaining unselected items should stay below the selected ones.
What I've Tried:
I tried sorting the options manually when the selection changes, but I couldn't achieve the desired behavior.
<p-multiSelect
[options]="sortedOptions"
[(ngModel)]="selectedValues"
optionLabel="name"
(onChange)="sortSelectedOptions()">
</p-multiSelect>
sortedOptions: any[] = [];
selectedValues: any[] = [];
options = [
{ name: 'Apple', value: 'apple' },
{ name: 'Orange', value: 'orange' },
{ name: 'Banana', value: 'banana' },
{ name: 'Mango', value: 'mango' }
];
ngOnInit() {
this.sortedOptions = [...this.options];
}
sortSelectedOptions() {
this.sortedOptions = [
...this.selectedValues,
...this.options.filter(opt => !this.selectedValues.includes(opt))
];
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the p-multiSelect component entry point and any existing component tests. Reproduce the selection behavior from the example in the issue, then verify how selected and unselected options are ordered, including repeated selection changes. Done means selected items appear first while unselected items retain their relative order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100