primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Multiselect Improvement

Open leoxgnr93 opened this issue 10 years ago • 7 comments

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.

issue

leoxgnr93 avatar Sep 29 '16 19:09 leoxgnr93

+1

emilioag avatar Oct 24 '16 16:10 emilioag

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 ;)

michalig avatar Oct 31 '16 10:10 michalig

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 {...}

zealitude avatar Nov 16 '16 08:11 zealitude

Same issue for me. Do you know if something is planned ?

Axel-Latour avatar Nov 21 '16 15:11 Axel-Latour

Same issue for me too. Any plans to push this code

mohan1304 avatar Jan 02 '17 08:01 mohan1304

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>

PyroXn avatar Jan 13 '17 09:01 PyroXn

Please try with the latest PrimeNG version and comment if the issue still persists.

Mrtcndkn avatar May 04 '17 12:05 Mrtcndkn