2

Using PrimeNg p-dropdown in component.

<p-dropdown 
 [options]="productRequest"
 formControlName="request"
 optionLabel="ProductName"
 (onChange)="someFunction('request')">
</p-dropdown>

Below is the JSON received from server that is used as [options] in p-dropdown

{ 
 "Increase": true,
 "Decrease" : true,
 "Like" : true,
 "Dislike" : true,
 "Old" : false,
 "Others" : true
}

I need to disable that option against which boolean: false is mentioned. Like while i click on dropdown, i am able to see all options. Now i need to disable that particular option against which boolean: false is mentioned. In above case i should be able to select all options except Old as it has boolean: false against it.

How to do so ?? Thanks in advance..

  • Does this answer your question? [PrimeNG dropdown - disable certain SelectItems](https://stackoverflow.com/questions/43873162/primeng-dropdown-disable-certain-selectitems) – Eldar Sep 26 '20 at 19:12
  • @Eldar: Unable to identify actually what that workaround is, hence unable to implement it. If possible can you please tell me what it's saying. –  Sep 27 '20 at 06:46
  • Any way @Eldar: to get specific dropdown option property on page load or on mouseclick as soon as we click to see list of options ?? If I get it, I can apply disable attribute –  Sep 27 '20 at 06:50

1 Answers1

3

To disable specific options using the dropdown component of prime-ng, you must use SelectItem type when constructing your array.

Within the SelectItem type there is a disabled property of type boolean.

This is where you can disable a specific option by setting this property to true.

I have created you a Stackblitz with a working example here:

https://stackblitz.com/edit/primeng-dropdown-demo-m6a6ni

Happy Coding :-)

Adamski
  • 839
  • 2
  • 10
  • 28
  • 1
    Unable to include that workaround in my case.. As per your reference I just need to add and option.disabled, but it's not working for me –  Sep 27 '20 at 06:42
  • Any way to get specific dropdown option property on page load or on mouseclick as soon as we click to see list of options. There I can apply disable attribute to that option –  Sep 27 '20 at 06:52
  • @rose - no need to work around , solution is in the updated the answer for you :-) – Adamski Sep 27 '20 at 07:28
  • thanks very much it solved my query, hence marking it as answer :) –  Sep 27 '20 at 13:58