You can disable any item in dropdown using ng-template, click event and custom style, like this:
Code: Select all
cars: any[];
selectedCar: string;
ngOnInit(): void {
this.cars = [];
this.cars.push({label: 'Audi', value: 'Audi'});
this.cars.push({label: 'BMW', value: 'BMW'});
this.cars.push({label: 'Fiat', value: 'Fiat', disabled: true});
this.cars.push({label: 'Ford', value: 'Ford'});
this.cars.push({label: 'Honda', value: 'Honda', disabled: true});
this.cars.push({label: 'Jaguar', value: 'Jaguar'});
this.cars.push({label: 'Mercedes', value: 'Mercedes'});
this.cars.push({label: 'Renault', value: 'Renault'});
this.cars.push({label: 'VW', value: 'VW'});
this.cars.push({label: 'Volvo', value: 'Volvo'});
}
onClick(disabled: boolean) {
if(disabled) {
event.stopPropagation();
}
}
Code: Select all
<p-dropdown [options]="cars" [(ngModel)]="selectedCar" [style]="{'width':'150px'}">
<ng-template let-option pTemplate="item">
<div>
<div (click)="onClick(option.disabled)" [ngStyle]="option.disabled? {'color': '#ccc', 'cursor': 'default'} : ''">{{option.label}}</div>
</div>
</ng-template>
</p-dropdown>