Multiselect Improvement
Multiselect is a great feature but it has a little issue
- The component tends to growing up (width & height) according with the data
One improvement if it is possible to include is the option to show just a name instead the items list
I would appreciate that this could happen soon. Thanks.

+1
Hi @leoxgnr93
What I came up with is a function you can overwrite in order to fully customize the label. Please take a look at code here: https://github.com/nadirowski/primeng-jit/commit/dd5be230befe86e7aa1b9260892e99c0cda6df9a and demo here: https://github.com/nadirowski/primeng-jit/commit/40aa5c3114a8e21e3c8c34903a805fa4d34afa78
What you can do with it is for example show the number of selected items instead of items itself or fix annoying "," separator (without space ;)).
Everything you have to do is to provide function with signature as below:
public updateLabel(items:any[], defaultLabel:string): string {...}
To show the number of items just do:
public updateLabel(items:any[], defaultLabel:string): string {
if (items && items.length) {
return "Chosen: " + items.length;
} else {
return defaultLabel;
}
}
It is not in the main codebase yet but if you find it useful I we try to push it there ;)
I am facing the exactly issue. @michalig Hi, it will good to introduce custom label function
ps. suggest to change the interface to selectedItems in order to avoid confusing public updateLabel(selectedItems:any[], defaultLabel:string): string {...}
Same issue for me. Do you know if something is planned ?
Same issue for me too. Any plans to push this code
My solution
import {Directive, Input, ElementRef} from "@angular/core";
@Directive({
selector: '[forceLabel]'
})
export class ForceLabelDirective {
@Input() forceLabel: string;
constructor(private el: ElementRef) {
}
ngOnInit() {
if (this.forceLabel) {
let label: HTMLLabelElement = this.el.nativeElement.querySelector('label');
label.textContent = this.forceLabel;
}
}
}
<p-multiSelect [forceLabel]="'Status'" [options]="statusFilter" [(ngModel)]="mission.status" (onChange)="findViolations()"></p-multiSelect>
Please try with the latest PrimeNG version and comment if the issue still persists.