function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shyamala VaradharajanShyamala Varadharajan 

Picklist field is disabled in LWC Datatable

I have a picklist field which I am fetching data from Apex. Now the scenario is I have to fetch all the data and I'm able to see those values in console.log but the picklist field looks greyed out and not able to edit even after adding wrapText=true. I created custom type for picklist. The values are not visible. Do you have any idea what I am doing wrong? Please help me on this.

User-added image

User-added image

Here is my code:
aRADataTable.html:
<template>
    <lightning-card>
        <c-custom-type-global
        data={dataRecords}
        columns={columns}
        key-field="Id"
        suppress-bottom-bar
        oncellchange={handleSave}
        draft-values={saveDraftValues}
        errors={errors}
        wrap-text-max-lines=3
        hide-checkbox-column
        horizontal-scroll-hidden
        onkeyup={changeInTable}>
    </c-custom-type-global>
        </lightning-card>
</template>

aRADataTable.js:

import { LightningElement, track,api } from 'lwc';
import fetchInventoryDataTableRecords from '@salesforce/apex/ARAInventoryTypeUpgrade.fetchInventoryDataTableRecords';

export default class ARADataTable extends LightningElement {
    @track columns;
    @track allInvTypes = [];
    @track dataRecords = [];
    @track pickListOptions = [];
    @api options;
   
    connectedCallback() {
       
        this.columns = [{ label: 'Inventory Type', fieldName: 'inventoryTypeCode', type: 'text', wrapText: true, hideDefaultActions: 'true' },
        { label: 'Priority 1', fieldName: 'p1', type: 'priorityPicklist', wrapText: true,
        typeAttributes:{
         //   options: this.pickListOptions,
           options: { fieldName: 'pickListOptions' },
            value :{fieldName : 'Priority'},
            placeholder: 'Choose Priority'
        }  
    }
];
    fetchInventoryDataTableRecords()
        .then(result => {
           
            let options=[];
            this.dataRecords = result;
            this.defaultDataTableValues = this.dataRecords;
            for (var i = 0; i < this.dataRecords.length; i++) {
                //Taking one data value of row at a time
                const item = this.dataRecords[i];
                this.allInvTypes.push(item.inventoryTypeCode);
                options.push(item.inventoryTypeCode);
            }
             this.pickListOptions.push(options);
            console.log('picklistOptions>>>>'+this.pickListOptions);
            return this.pickListOptions;
          })
        .catch(error => {
            console.error(error.message);
        });
      }
}

customPicklist.html

<template>
    <lightning-combobox
      name="picklist"
      label={typeAttributes.label}
      value={typeAttributes.value}
      placeholder={typeAttributes.placeholder}
      options={typeAttributes.options}
    ></lightning-combobox>
</template>

customTypeGlobal.js

import LightningDatatable from 'lightning/datatable';
import customPicklist from './customPicklist.html';
export default class CustomTypeGlobal extends LightningDatatable {
    static customTypes = {
        priorityPicklist:{
            template : customPicklist,
            standardCellLayout: true,
            typeAttributes:['label','value','placeholder','options']
        }
    }
}
AshwiniAshwini (Salesforce Developers) 
Hi Shyamala,

Issue seems to be with the way you are handling the picklist options in your code.
You are pushing an array of options for each record into this.pickListOptions, which results in a nested array structure. This is incorrect because the custom picklist component expects a flat list of options, not nested arrays.

To fix the issue, instead of pushing arrays of options for each record, you can concatenate all the picklist options into a single flat array. 

You can refer below logic and make adjustments:
this.pickListOptions = [];
for(var i = 0; i < this.dataRecords.length; i++) 
{ 
const item = this.dataRecords[i]; this.allInvTypes.push(item.inventoryTypeCode); options.push(item.inventoryTypeCode); 
} 
this.pickListOptions = options;

Make sure that the data you are fetching from Apex for the 'Priority 1' field ('p1') contains valid picklist values.

If this information helps, please mark the answer as best. Thank you
 
Shyamala VaradharajanShyamala Varadharajan
Hi Ashwini,

Thank you for your response I tried but no luck :(..