Lightning Data Table inline editUnderstanding Lightning interactions - How does Lightning component and...
Modern Algebraic Geometry and Analytic Number Theory
Why did Mr. Elliot have to decide whose boots were thickest in "Persuasion"?
Was there a pre-determined arrangement for the division of Germany in case it surrendered before any Soviet forces entered its territory?
How to politely refuse in-office gym instructor for steroids and protein
Are all power cords made equal?
Buying a "Used" Router
Where does documentation like business and software requirement spec docs fit in an agile project?
Is there any way to make an Apex method parameter lazy?
Eww, those bytes are gross
How to create a label containing values from different layers in QGIS
Caron Accent v{a} doesn't render without usepackage{xeCJK}
"Starve to death" Vs. "Starve to the point of death"
Why some papers can be published in top-tier journals while others cannot?
Boss asked me to sign a resignation paper without a date on it along with my new contract
How vim overwrites readonly mode?
Possible issue with my W4 and tax return
Does it take energy to move something in a circle?
Does the US government have any planning in place to ensure there's no shortages of food, fuel, steel and other commodities?
Why do neural networks need so many examples to perform?
How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?
Critique vs nitpicking
Charging phone battery with a lower voltage, coming from a bike charger?
Renting a 2CV in France
What can I do to encourage my players to use their consumables?
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 1 hour ago
McH2000McH2000
818
818
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 1 hour 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