Skip to main content
lightning work a posé une question dans #Lightning Experience
Hi,

I can able to hide the checkbox in lwc data table , but how to add input number ?

Similar funtionality based on input number i have to add records

Any idea please ?

Thanks

KMK
1 réponse
  1. 3 oct. 2023, 12:14

    Hi KMK91,

    • As you mentioned you are able to hide the checkbox in the lwc data table.
    • Please try the below code and take a reference.

    <template>

    <lightning-datatable

    key-field="id"

    columns={columns}

    data={lstRecords}

    >

    </lightning-datatable>

    </template>

    ---------------------------------

    import { LightningElement,wire } from 'lwc';

    import getRecords from '@salesforce/apex/fetchAccount.getRecords';

    export default class ShowSeperateRowColumn extends LightningElement {

    columns = [{label : 'Row Number', fieldName : 'rowNumber',type : 'number'},

    {label : 'Name', fieldName : 'Name',type : 'text'},

    {label : 'Phone', fieldName : 'Phone',type : 'text'},

    {label : 'Type', fieldName : 'type',type : 'text'}];

    lstRecords;

    @wire (getRecords)fetchData(value) {

    const {

    data,

    error

    } = value;

    if (data) {

    let result = JSON.parse(JSON.stringify(data));

    console.log('result==> ' + JSON.stringify(result));

    for(var i=0; i<result.length; i++){

    result[i].rowNumber = i+1;

    }

    this.lstRecords = result;

    }

    else if(error){

    console.log(error);

    this.lstRecords = [];

    }

    }

    }

    ---------------------------------------------------

    public with sharing class fetchAccount {

    @AuraEnabled(Cacheable=true)

    public static List<Account> getRecords(){

    return [SELECT Id,Name,Phone,type From Account];

    }

    }

    Please mark it as Best Answer if the above information was helpful.

    Thanks.

     
0/9000