[SalesForce] How to hide the default row number from the first column in a lightning-datatable (LWC)

I have tried using the show-row-number-column = "false" attribute but it does not seem to work.

https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/specification

    <div class="slds-m-around_medium">
        <template if:true={voting}>
            <lightning-datatable
                key-field="Id"
                hide-checkbox-column = "true"
                data={voting}
                columns={columns}
                onsave={handleSave} 
                show-row-number-column = "false"  
                draft-values={draftValues}>
            </lightning-datatable>
        </template>
        <template if:true={voting}>
            <!-- handle Apex error -->
        </template>
    </div>

Best Answer

The attribute show-row-number-column set automatically to "true" if present we dont need to set it to "true" or "false" if you dont want row number Simply remove that attribute

  <lightning-datatable
                key-field="Id"
                hide-checkbox-column = "true"
                data={voting}
                columns={columns}
                onsave={handleSave} 

                draft-values={draftValues}>
            </lightning-datatable>

Also if the columns are editable,the show-row-number-column attribute is always true and the number column is displayed.

Related Topic