1

I'm working with an example from: https://live.playg.app/play/picklist-in-lightning-datatable

I need to be able to dynamically set the Rating options that are hard-coded below ({ label: 'Hot', value: 'Hot' } . . .)

this.columns = [
    { label: 'Name', fieldName: 'Name', editable: true },
    { label: 'Account Number', fieldName: 'AccountNumber', editable: true },
    { label: 'Phone', fieldName: 'phone', type: 'phone', editable: true },
    {
        label: 'Rating', fieldName: 'Rating', type: 'picklist', typeAttributes: {
            placeholder: 'Choose rating', options: [
                { label: 'Hot', value: 'Hot' },
                { label: 'Warm', value: 'Warm' },
                { label: 'Cold', value: 'Cold' },
            ] // list of all picklist options
            , value: { fieldName: 'Rating' } // default value for picklist
            , context: { fieldName: 'Id' } // binding account Id with context variable to be returned back
        }
    }
];

Seems like it should be pretty simple but I have not made it work yet. I've tried to shoehorn this into it with no luck:

this.options= [{label: 'TEST1', value: 'a5l350000'},
                            {label: 'TEST2', value: 'a5l35222'}];

and then putting this.options in the columns json instead of the hard-coded part that is in there.

Any help appreciated.

4

1 Answer 1

0

You can do something like below:

this.columns = [
    { label: 'Name', fieldName: 'Name', editable: true },
    { label: 'Account Number', fieldName: 'AccountNumber', editable: true },
    { label: 'Phone', fieldName: 'phone', type: 'phone', editable: true },
    {
        label: 'Rating', fieldName: 'Rating', type: 'picklist', typeAttributes: {
            placeholder: 'Choose rating', options:this.getPLValues// list of all picklist options
            , value: { fieldName: 'Rating' } // default value for picklist
            , context: { fieldName: 'Id' } // binding account Id with context variable to be returned back
        }
    }
];

...
...
    getPLValues() {
        var plValues = [];
        plValues.push({ label: 'Complete', value: 'Complete' });
        plValues.push({ label: 'Rejected', value: 'Rejected' });
        plValues.push({ label: 'Waived', value: 'Waived' });

        return plValues;
//this gets called only once though, not once per row. That is where I am stuck. 
    }
2
  • Here where you are stuck you should call the Apex method to bring all the picklist values for the object you´re using May 22, 2022 at 18:44
  • 1
    Where'd you get the "type: picklist" from? It's not an available value Jun 15, 2022 at 6:39

You must log in to answer this question.

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