primefaces / primefaces/primeng

PrimeNG p-multiSelect: Keep Selected Items on Top

Open
#17,544 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Resolution: Stale Status: Needs Triage
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.