Lightning Data Table inline editUnderstanding Lightning interactions - How does Lightning component and...
Subsurf on a crown. How can I smooth some edges and keep others sharp?
Plausible reason for gold-digging ant
If angels and devils are the same species, why would their mortal offspring appear physically different?
Why is that max-Q doesn't occur in transonic regime?
"Starve to death" Vs. "Starve to the point of death"
Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?
Plausible reason to leave the Solar System?
A fantasy book with seven white haired women on the cover
What senses are available to a corpse subjected to a Speak with Dead spell?
Single-row INSERT...SELECT much slower than separate SELECT
Non-Cancer terminal illness that can affect young (age 10-13) girls?
How to politely refuse in-office gym instructor for steroids and protein
Book where a space ship journeys to the center of the galaxy to find all the stars had gone supernova
Equivalent of "illegal" for violating civil law
Article. The word "Respect"
How to completely remove a package in Ubuntu (like it never existed)
Does the ditching switch allow an A320 to float indefinitely?
How to create a label containing values from different layers in QGIS
How do you funnel food off a cutting board?
What is a good reason for every spaceship to carry a weapon on board?
Eww, those bytes are gross
Is there a way to not have to poll the UART of an AVR?
Can a player sacrifice a creature after declaring that creature as blocker while taking lethal damage?
What to do with threats of blacklisting?
Lightning Data Table inline edit
Understanding Lightning interactions - How does Lightning component and controller (.js) calls apex class controller and interact with it?Lightning card with a data table insidelightning:recordEditForm basically 'Dies' during random situationslightning:datatable component - hiding Save and Cancel buttons after inline editsave two records in two objects with a single save button with lightning componentsHelp with working with lightning:dataTable?Are Address fields are restricted to save in LDS?Url field type is not working in Lightning data tableRendering data from Wrapper Class into Lightning Data tableLightning Gantt Chart Development
How best to update records with changes made in a lightning datatable? The original list of accounts is not automatically updated by inline changes, and the 'draftValues' retrieved when the update 'save' button is clicked, don't have the ID of the record, so I can't update.
For example, when I click update, I get
draftvalues: [{"Industry":"kjnkjnk","id":"row-0"}]
acctList: [{"Id":"001n000000UX9ZYAA2","Name":"CIA","Type":"Prospect"},{"Id":"001n000000UXByNAAX","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXBmdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAfYAA1","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAAdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXB8SAA5","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAPDC23","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXASMZX3","Name":"Company","Type":"Prospect"}]
So, first list doesn't have ids, and second lot doesn't have changes = can't update.
Do I have to manually associate the 'draftvalues' with the id of the record, or is there some easier way to do this?
I have:
cmp:
<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute name="sortedBy" type="String" default="Name"/>
<aura:attribute name="sortedDirection" type="String" default="asc"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{!v.acctList}"
columns="{!v.mycolumns}"
keyField="id"
hideCheckboxColumn="true"
onsort="{!c.updateColumnSorting}"
sortedBy="{!v.sortedBy}"
sortedDirection="{!v.sortedDirection}"
onsave="{! c.handleSave }"/>
controller.js:
fetchAccounts : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Account Name', fieldName: 'Name', type: 'text', sortable: true, editable: true},
{label: 'Industry', fieldName: 'Industry', type: 'text', sortable: true, editable: true},
{label: 'Type', fieldName: 'Type', type: 'Text', sortable: true, editable: true}
]);
var action = component.get("c.fetchAccts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
helper.sortData(component, component.get("v.sortedBy"), component.get("v.sortedDirection"));
}
});
$A.enqueueAction(action);
},
handleSave: function(cmp, event, helper){
var action = cmp.get("c.saveAccts");
var acctList = cmp.get("v.acctList");
var draftList = event.getParam('draftValues');
console.log('draftValues-> ' + JSON.stringify(draftList));
console.log('acctList->' + JSON.stringify(acctList));
console.log(acctList);
action.setParams({acctList: draftList});
action.setCallback(this, function(response){
console.log('hi');
});
$A.enqueueAction(action);
AccountListController.apxc:
@AuraEnabled
public static List < Account > fetchAccts() {
return [ SELECT Id, Name, Industry, Type FROM Account LIMIT 10 ];
}
@AuraEnabled
public static String saveAccts(List<account> acctList){
System.debug(acctList);
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
update acctList;
return 'hi';
}
lightning-aura-components lightning lightning-datatable
add a comment |
How best to update records with changes made in a lightning datatable? The original list of accounts is not automatically updated by inline changes, and the 'draftValues' retrieved when the update 'save' button is clicked, don't have the ID of the record, so I can't update.
For example, when I click update, I get
draftvalues: [{"Industry":"kjnkjnk","id":"row-0"}]
acctList: [{"Id":"001n000000UX9ZYAA2","Name":"CIA","Type":"Prospect"},{"Id":"001n000000UXByNAAX","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXBmdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAfYAA1","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAAdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXB8SAA5","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAPDC23","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXASMZX3","Name":"Company","Type":"Prospect"}]
So, first list doesn't have ids, and second lot doesn't have changes = can't update.
Do I have to manually associate the 'draftvalues' with the id of the record, or is there some easier way to do this?
I have:
cmp:
<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute name="sortedBy" type="String" default="Name"/>
<aura:attribute name="sortedDirection" type="String" default="asc"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{!v.acctList}"
columns="{!v.mycolumns}"
keyField="id"
hideCheckboxColumn="true"
onsort="{!c.updateColumnSorting}"
sortedBy="{!v.sortedBy}"
sortedDirection="{!v.sortedDirection}"
onsave="{! c.handleSave }"/>
controller.js:
fetchAccounts : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Account Name', fieldName: 'Name', type: 'text', sortable: true, editable: true},
{label: 'Industry', fieldName: 'Industry', type: 'text', sortable: true, editable: true},
{label: 'Type', fieldName: 'Type', type: 'Text', sortable: true, editable: true}
]);
var action = component.get("c.fetchAccts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
helper.sortData(component, component.get("v.sortedBy"), component.get("v.sortedDirection"));
}
});
$A.enqueueAction(action);
},
handleSave: function(cmp, event, helper){
var action = cmp.get("c.saveAccts");
var acctList = cmp.get("v.acctList");
var draftList = event.getParam('draftValues');
console.log('draftValues-> ' + JSON.stringify(draftList));
console.log('acctList->' + JSON.stringify(acctList));
console.log(acctList);
action.setParams({acctList: draftList});
action.setCallback(this, function(response){
console.log('hi');
});
$A.enqueueAction(action);
AccountListController.apxc:
@AuraEnabled
public static List < Account > fetchAccts() {
return [ SELECT Id, Name, Industry, Type FROM Account LIMIT 10 ];
}
@AuraEnabled
public static String saveAccts(List<account> acctList){
System.debug(acctList);
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
update acctList;
return 'hi';
}
lightning-aura-components lightning lightning-datatable
add a comment |
How best to update records with changes made in a lightning datatable? The original list of accounts is not automatically updated by inline changes, and the 'draftValues' retrieved when the update 'save' button is clicked, don't have the ID of the record, so I can't update.
For example, when I click update, I get
draftvalues: [{"Industry":"kjnkjnk","id":"row-0"}]
acctList: [{"Id":"001n000000UX9ZYAA2","Name":"CIA","Type":"Prospect"},{"Id":"001n000000UXByNAAX","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXBmdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAfYAA1","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAAdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXB8SAA5","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAPDC23","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXASMZX3","Name":"Company","Type":"Prospect"}]
So, first list doesn't have ids, and second lot doesn't have changes = can't update.
Do I have to manually associate the 'draftvalues' with the id of the record, or is there some easier way to do this?
I have:
cmp:
<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute name="sortedBy" type="String" default="Name"/>
<aura:attribute name="sortedDirection" type="String" default="asc"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{!v.acctList}"
columns="{!v.mycolumns}"
keyField="id"
hideCheckboxColumn="true"
onsort="{!c.updateColumnSorting}"
sortedBy="{!v.sortedBy}"
sortedDirection="{!v.sortedDirection}"
onsave="{! c.handleSave }"/>
controller.js:
fetchAccounts : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Account Name', fieldName: 'Name', type: 'text', sortable: true, editable: true},
{label: 'Industry', fieldName: 'Industry', type: 'text', sortable: true, editable: true},
{label: 'Type', fieldName: 'Type', type: 'Text', sortable: true, editable: true}
]);
var action = component.get("c.fetchAccts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
helper.sortData(component, component.get("v.sortedBy"), component.get("v.sortedDirection"));
}
});
$A.enqueueAction(action);
},
handleSave: function(cmp, event, helper){
var action = cmp.get("c.saveAccts");
var acctList = cmp.get("v.acctList");
var draftList = event.getParam('draftValues');
console.log('draftValues-> ' + JSON.stringify(draftList));
console.log('acctList->' + JSON.stringify(acctList));
console.log(acctList);
action.setParams({acctList: draftList});
action.setCallback(this, function(response){
console.log('hi');
});
$A.enqueueAction(action);
AccountListController.apxc:
@AuraEnabled
public static List < Account > fetchAccts() {
return [ SELECT Id, Name, Industry, Type FROM Account LIMIT 10 ];
}
@AuraEnabled
public static String saveAccts(List<account> acctList){
System.debug(acctList);
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
update acctList;
return 'hi';
}
lightning-aura-components lightning lightning-datatable
How best to update records with changes made in a lightning datatable? The original list of accounts is not automatically updated by inline changes, and the 'draftValues' retrieved when the update 'save' button is clicked, don't have the ID of the record, so I can't update.
For example, when I click update, I get
draftvalues: [{"Industry":"kjnkjnk","id":"row-0"}]
acctList: [{"Id":"001n000000UX9ZYAA2","Name":"CIA","Type":"Prospect"},{"Id":"001n000000UXByNAAX","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXBmdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAfYAA1","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAAdAAP","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXB8SAA5","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXAPDC23","Name":"Company","Type":"Prospect"},{"Id":"001n000000UXASMZX3","Name":"Company","Type":"Prospect"}]
So, first list doesn't have ids, and second lot doesn't have changes = can't update.
Do I have to manually associate the 'draftvalues' with the id of the record, or is there some easier way to do this?
I have:
cmp:
<aura:attribute type="Account[]" name="acctList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute name="sortedBy" type="String" default="Name"/>
<aura:attribute name="sortedDirection" type="String" default="asc"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
<lightning:datatable data="{!v.acctList}"
columns="{!v.mycolumns}"
keyField="id"
hideCheckboxColumn="true"
onsort="{!c.updateColumnSorting}"
sortedBy="{!v.sortedBy}"
sortedDirection="{!v.sortedDirection}"
onsave="{! c.handleSave }"/>
controller.js:
fetchAccounts : function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Account Name', fieldName: 'Name', type: 'text', sortable: true, editable: true},
{label: 'Industry', fieldName: 'Industry', type: 'text', sortable: true, editable: true},
{label: 'Type', fieldName: 'Type', type: 'Text', sortable: true, editable: true}
]);
var action = component.get("c.fetchAccts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
helper.sortData(component, component.get("v.sortedBy"), component.get("v.sortedDirection"));
}
});
$A.enqueueAction(action);
},
handleSave: function(cmp, event, helper){
var action = cmp.get("c.saveAccts");
var acctList = cmp.get("v.acctList");
var draftList = event.getParam('draftValues');
console.log('draftValues-> ' + JSON.stringify(draftList));
console.log('acctList->' + JSON.stringify(acctList));
console.log(acctList);
action.setParams({acctList: draftList});
action.setCallback(this, function(response){
console.log('hi');
});
$A.enqueueAction(action);
AccountListController.apxc:
@AuraEnabled
public static List < Account > fetchAccts() {
return [ SELECT Id, Name, Industry, Type FROM Account LIMIT 10 ];
}
@AuraEnabled
public static String saveAccts(List<account> acctList){
System.debug(acctList);
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
update acctList;
return 'hi';
}
lightning-aura-components lightning lightning-datatable
lightning-aura-components lightning lightning-datatable
asked 6 hours ago
McH2000McH2000
838
838
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The keyField should be Id
, not id
. Note that JavaScript is case sensitive, and as such, Lightning is also case-sensitive. You should get the correct Id so long as you use the correct casing.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f251592%2flightning-data-table-inline-edit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The keyField should be Id
, not id
. Note that JavaScript is case sensitive, and as such, Lightning is also case-sensitive. You should get the correct Id so long as you use the correct casing.
add a comment |
The keyField should be Id
, not id
. Note that JavaScript is case sensitive, and as such, Lightning is also case-sensitive. You should get the correct Id so long as you use the correct casing.
add a comment |
The keyField should be Id
, not id
. Note that JavaScript is case sensitive, and as such, Lightning is also case-sensitive. You should get the correct Id so long as you use the correct casing.
The keyField should be Id
, not id
. Note that JavaScript is case sensitive, and as such, Lightning is also case-sensitive. You should get the correct Id so long as you use the correct casing.
answered 6 hours ago
sfdcfoxsfdcfox
256k11201442
256k11201442
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f251592%2flightning-data-table-inline-edit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown