0

I have implemented a lightning-combobox using getPicklistValues, which works as expected as I can see all my picklist values. Here is my implementation:

JS:

@track modelValue= 'All';

@wire(getObjectInfo, { objectApiName: CUSTOM_OBJ})
customObjectInfo;

@wire(getPicklistValues, {
  recordTypeId: "$customObjectInfo.data.defaultRecordTypeId",
  fieldApiName: MY_MODEL
})
modelPicklistValues;

HTML:

<template if:true={modelPicklistValues.data} >
      <lightning-combobox name="models" label="Models" 
         value ={modelValue} placeholder="Select" options={modelPicklistValues.data.values} 
         onchange={handleModelsChange}>
      </lightning-combobox>
</template>

I would need this Picklist field to be used as a Filter. So, I would like to have the first value to be 'All', thus include the @track modelValue= 'All'; and assigned it my lightning-combobox.

All I could see is - Picklist field with placeholder 'Select' (as expected) and actual picklist values beneath it, but not 'All' as the first option. Is my understanding right? Can we get the first value other than what we have in the schema for the picklist values? I would need 'All' value for reapplying the filter when the user wanted to see results of all models.

1 Answer 1

1

You should be able to assign your modelPicklistValues.data.values to a property in your js controller and add the All value for it to be displayed and selectable in your template.

for example:

this.prop = [...modelPicklistValues.data.values] 
5
  • I am getting some typeError while trying to push 'All' value to a new property. If you don't mind, can you please share some basic code snippet? Thanks.
    – SatyaV
    Aug 11, 2021 at 19:57
  • this.prop = [...modelPicklistValues.data.values] ?
    – glls
    Aug 11, 2021 at 20:27
  • I was able to add the values to different property, but unable to add 'All' value to this new property.
    – SatyaV
    Aug 11, 2021 at 21:49
  • Never mind, I was able to do it by pushing the value with all the required key-values: var allPickListVal = {"attributes":null,"label":"All","validFor":[],"value":"All"};
    – SatyaV
    Aug 11, 2021 at 22:00
  • 1
    Awesome, glad you were able to figure it out. hope my answer helped =P
    – glls
    Aug 12, 2021 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .