Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter in multiple labels with p-listbox?

i want to filter on multiple labels , is there a way that optionLabel can have multiple options ?

<p-listbox [options]="sites" `enter code here`[(ngModel)]="selectedSite" class="ui-fluid" [listStyle]="{'max-height':'300px'}" filter="filter" optionLabel="name">

              <p-header>
                <strong>{{ 'select-site.choose' | translate}}</strong>
              </p-header>
              <ng-template let-site pTemplate="item">
                <span>{{site.value.code}} - {{site.value.name}}</span>
              </ng-template>
</p-listbox>

i want to filter on code and name

like image 561
Saad Doublali Avatar asked Nov 07 '22 17:11

Saad Doublali


1 Answers

Instead of setting options to an array of arbitrary objects, set it to an array of select items, with a label that contains both values you want to filter on.

siteOptions: SelectItem[] = sites.map(s => { value: s, label: s.name + s.code });

Update your listbox element:

<p-listbox [options]="siteOptions" [(ngModel)]="selectedSite" class="ui-fluid" [listStyle]="{'max-height':'300px'}" filter="filter">

You are already using an item template to control how each element in the list is displayed, so no other changes may be necessary.

like image 194
Ed Hickey Avatar answered Nov 14 '22 10:11

Ed Hickey