简体   繁体   中英

Is there any way to add divider or separator in PrimeNG P-dropdown value set

I am using Angular P-dropdown functionality, data will be populated from db, I will need to add divider after each set of key.

ie/

  1. add divider after gender key last value
  2. add divider after group key last value
<p-dropdown placeholder="Select" [options]="optionsArray" [(ngModel)]="selectOption"
            (ngModelChange)="triggerOption($event)" dropdownIcon="icons-down">
</p-dropdown>
//dynamic value from db
var ab =  [
   { label: "group 3", value: { key: 'group', value: '3' } },
   { label: "Female", value: { key: 'gender', value: 'F' } },
   { label: "New", value: { key: 'action', value: "New Action" } },
   { label: "group 1", value: { key: 'group', value: '1' } },
   { label: "group 2", value: { key: 'group', value: '2' } },
   { label: "Male", value: { key: 'gender', value: "Male" } },
   { label: "Old", value: { key: 'action', value: "Old" } },
   { label: "Not required", value: { key: 'action', value: "ACnotReq" } },
   
];

var newGenderArray = ab.filter(type  => {
 return type.value.key == 'gender';
});
 var newGroupArray =ab.filter(type => {
   return type.value.key == 'group';
 })
 ...,// logic
 var  optionsArray = newGenderArray.concat(newGroupArray);
console.log("optionsArray:", optionsArray);

tried the following CSS in static way,needed this as dynamic since values are coming from db, count is getting changed.

.ui-dropdown-items li:nth-child(3), .ui-dropdown-items li:nth-child(8) {
    border-bottom: 1px solid #dbdbdb;
   ...
}

Expected Result: 在此处输入图像描述

tried advance filtering something like this:

<h5>Content with Filters</h5>
<p-dropdown [options]="countries" [(ngModel)]="selectedCountry" optionLabel="name" [filter]="true" filterBy="name" [showClear]="true" placeholder="Select a Country">
    <ng-template pTemplate="selectedItem">
        <div class="country-item country-item-value"  *ngIf="selectedCountry">
            <img src="assets/showcase/images/demo/flag/flag_placeholder.png" [class]="'flag flag-' + selectedCountry.code.toLowerCase()" />
            <div>{{selectedCountry.name}}</div>
        </div>
    </ng-template>
    <ng-template let-country pTemplate="item">
        <div class="country-item">
            <img src="assets/showcase/images/demo/flag/flag_placeholder.png" [class]="'flag flag-' + country.code.toLowerCase()" />
            <div>{{country.name}}</div>
        </div>
    </ng-template>
</p-dropdown>

based from https://primefaces.org/primeng/showcase/#/dropdown

in the ng-template you can modify its content including adding some conditions and add a divider

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM