You need to sign in to do that
Don't have an account?

Autosave columns
Hi!
I need to create a TITLE and PHONE columns with autosave. When entering the new value of the field this value should be saved in the database automatically (user should not click on some button) like on this image:

Please tell me how can I do that.
My code:
Html:
<template>
<lightning-card title="Leads">
<lightning-layout multiple-rows="true" vertical-align="end">
<lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js:
import { LightningElement , wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
const columns = [
{ label: 'Name', fieldName: 'recordLink', type: 'url',
typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
{ label: 'Title', fieldName: 'Title', type: 'text', editable: true },
{ label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }
];
export default class LeadTable extends LightningElement {
columns = columns;
leads;
@wire(getLeads)
wiredLeads(value) {
const {error, data} = value;
if (data) {
let leadData = JSON.parse(JSON.stringify(data));
leadData.forEach(record => {
record.recordLink = "/" + record.Id;
record.LeadName = record.Name;
});
this.leads = leadData;
} else if (error) {
this.error = error;
}
}
}
Apex:
public with sharing class Qqq {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
];
return leads;
}
}
I need to create a TITLE and PHONE columns with autosave. When entering the new value of the field this value should be saved in the database automatically (user should not click on some button) like on this image:
Please tell me how can I do that.
My code:
Html:
<template>
<lightning-card title="Leads">
<lightning-layout multiple-rows="true" vertical-align="end">
<lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js:
import { LightningElement , wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
const columns = [
{ label: 'Name', fieldName: 'recordLink', type: 'url',
typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
{ label: 'Title', fieldName: 'Title', type: 'text', editable: true },
{ label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }
];
export default class LeadTable extends LightningElement {
columns = columns;
leads;
@wire(getLeads)
wiredLeads(value) {
const {error, data} = value;
if (data) {
let leadData = JSON.parse(JSON.stringify(data));
leadData.forEach(record => {
record.recordLink = "/" + record.Id;
record.LeadName = record.Name;
});
this.leads = leadData;
} else if (error) {
this.error = error;
}
}
}
Apex:
public with sharing class Qqq {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
];
return leads;
}
}
http://salesforceworld4u.blogspot.com/2013/01/autosave-feature-in-salesforce.html
check the above link. It may be useful for you. If yes, please mark as the best answer,
Thanks in advance