Activity Forums Salesforce® Discussions How to give input field in lightning:datatable?

  • Anurag

    Member
    September 5, 2018 at 2:15 pm

    Hi Prachi,

    To give an input field to a lightning datatable,

    • First make an attribute of the type list(say name-mycolumns).
    • Then, in an init function in a javascript controller, set this component with the field label , field type and any other thing if you want.Those are the things which are assigned to that 'mycolumn' atttrbute.
    • Lastly, get this attribute in column property of lightning:datatable  .

    Summary:

    Step 1:

    <aura:attribute name="mycolumns" type="List"/>

    Step 2:

    init: function (cmp, event, helper) {
    cmp.set('v.mycolumns', [
    {label: 'Contact Name', fieldName: 'Name', type: 'text'},
    {label: 'Phone', fieldName: 'Phone', type: 'phone'},
    ]);

    Step 3:

    <lightning:datatable columns="{! v.mycolumns }" />

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos