5

I am aware that lightning:datatable does not support picklists.

The approved attributes are:

  • action
  • boolean
  • button
  • button-icon
  • currency
  • date
  • date-local
  • email
  • location
  • number
  • percent
  • phone
  • text
  • url

With that said, I have a need for a picklist value to be visible and editable in my datatable (as I am sure many other people have run into). My question is - has anyone found a good workaround for this blocker yet?

My workaround thought is to use the action button and have a drop down of either hardcoded values or queried values. I am not entirely sure if this is possible as I don't see in the documentation any where that you can define a "default" value like you can with lightning attributes.

Does anyone know if this is possible?

({
    doInit: function (component , event, helper) {
    component.set('v.columns', [
        {label: 'Name', fieldName: 'Name', type: 'text', editable: true, typeAttributes: { required: false }},
        {label: 'Owner Name', fieldName: 'OwnerId.Name', type: 'lookup', editable: true, typeAttributes: { required: false }},
        {label: 'Type', fieldName: 'Type', type: 'action', editable: true, typeAttributes: {rowActions: actions } {defaultValues: 'value1', 'value2'}}, //PICKLIST
        {label: 'Tier', fieldName: 'Tier__c', type: 'action', editable: true, typeAttributes: {rowActions: actions }{defaultValues: 'value3', 'value4'}}, //PICKLIST
0

1 Answer 1

5

In Aura lightning:datatable, it is not possible to have custom components but in LWC lightning-datatable, it is possible to have custom component in table columns. Below are the steps:

  1. Create your custom component which has picklist.
  2. Create another component which extends LightningDatatable and declare/refer to template.
  3. Create the HTML template which uses the component in step:1 and should be in same folder as that of component in step:2 - this is same template which is referred in JS.
  4. Use the new component of step:2 wherever you need and have the picklist datatype.
  5. You also need a button to save the record(s). This Save button can be in column or as separate button above table which saves the records having picklist populated.

For detailed example of how to create this, you can refer to How to use custom LWC lightning component in lightning-datatable

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