You need to sign in to do that
Don't have an account?
Abhishek Sharma 527
unable to edit fields in lwc
Hello There, I have lwc which shows list of contact records and I added editable='true' in result page it's getting edit but not getting saved, I'm not sure where and how to query update query
Can anyone help me in writing code to save the updated record.
// html code
<template>
<h2> Contact Datatable</h2>
<lightning-datatable data={wiredContacts.data} columns={columns} key-field="Id">
</lightning-datatable>
</template>
// js code
import { LightningElement ,api, wire, track} from 'lwc';
import getContactList from '@salesforce/apex/method.getContactList';
export default class contactRecord extends LightningElement {
@track columns = [
{ label: 'Name', fieldName: 'Name', editable: true},
{ label: 'Id', fieldName: 'Id'},
{label: 'Email', fieldName: 'Email'}
];
@track conList;
@track error;
@wire(getContactList)
wiredContacts;
}
// class code
public with sharing class method {
@AuraEnabled(cacheable=true)
public static List<Contact> getContactList() {
return [SELECT Id, Name, email
FROM Contact];
}
}
Can anyone help me in writing code to save the updated record.
// html code
<template>
<h2> Contact Datatable</h2>
<lightning-datatable data={wiredContacts.data} columns={columns} key-field="Id">
</lightning-datatable>
</template>
// js code
import { LightningElement ,api, wire, track} from 'lwc';
import getContactList from '@salesforce/apex/method.getContactList';
export default class contactRecord extends LightningElement {
@track columns = [
{ label: 'Name', fieldName: 'Name', editable: true},
{ label: 'Id', fieldName: 'Id'},
{label: 'Email', fieldName: 'Email'}
];
@track conList;
@track error;
@wire(getContactList)
wiredContacts;
}
// class code
public with sharing class method {
@AuraEnabled(cacheable=true)
public static List<Contact> getContactList() {
return [SELECT Id, Name, email
FROM Contact];
}
}
Please follow bellow url that's will help to solve your problem:-
https://www.salesforcecodecrack.com/2020/12/inline-editing-in-lightning-datatable.html
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
There currently exists a 'updateRecord' adapter in LWC but it only updates a single record. The only other thing I could think off would be creating another method in your Apex helper class to handle saving the records. You will then call this method from your LWC once you're finished making the changes. Pass the records from the LWC to the Apex method via an argument as a String to be deserialized with the JSON class. Hope this helps.
I understand by creating seperate method it 'd solve but I'm not getting how to write method for that and link with LWC, if any prototype code or similar you can share, it will be great help.
Refer the below link will help you to create lwc data table with inlie edit.
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_table_inline_edit
https://techdicer.com/inline-editing-in-lightning-datatable-in-lwc-salesforce/
If this information helps, Please mark it as best answer.
Thanks!!
Please follow bellow url that's will help to solve your problem:-
https://www.salesforcecodecrack.com/2020/12/inline-editing-in-lightning-datatable.html
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh