Cannot populate data in lightning data tableLightning Event ModelAura StaticResource Javascript helper classesLightning development help with component refreshhow to save record of slider in object in lightningUnderstanding Lightning interactions - How does Lightning component and controller (.js) calls apex class controller and interact with it?How to call the setCallback function with a callback functionaction.setCallback not getting executed after $A.enqueueAction(action);save two records in two objects with a single save button with lightning componentsIssue in using wrapper class variable in Lightning componentLightning Gantt Chart Development
Why do people keep telling me that I am a bad photographer?
Using column size much larger than necessary
Is there an idiom that support the idea that "inflation is bad"?
If your medical expenses exceed your income does the IRS pay you?
Verb "geeitet" in an old scientific text
Should I replace my bicycle tires if they have not been inflated in multiple years
Where can I go to avoid planes overhead?
Missing Piece of Pie - Can you find it?
Fitch Proof Question
Building a list of products from the elements in another list
Why isn't nylon as strong as kevlar?
Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?
Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?
How long would it take for people to notice a mass disappearance?
Can my company stop me from working overtime?
I need a disease
Would glacier 'trees' be plausible?
Manager is threatening to grade me poorly if I don't complete the project
How can I support myself financially as a 17 year old with a loan?
Why are prions in animal diets not destroyed by the digestive system?
Upside-Down Pyramid Addition...REVERSED!
Position of past participle and extent of the Verbklammer
How do I tell my manager that his code review comment is wrong?
What is the most remote airport from the center of the city it supposedly serves?
Cannot populate data in lightning data table
Lightning Event ModelAura StaticResource Javascript helper classesLightning development help with component refreshhow to save record of slider in object in lightningUnderstanding Lightning interactions - How does Lightning component and controller (.js) calls apex class controller and interact with it?How to call the setCallback function with a callback functionaction.setCallback not getting executed after $A.enqueueAction(action);save two records in two objects with a single save button with lightning componentsIssue in using wrapper class variable in Lightning componentLightning Gantt Chart Development
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
<aura:component controller="DisplayconsClass">
<aura:attribute type="Contact[]" name="consList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="!this" action="!c.init"/>
<lightning:datatable keyField="id" data="!v.consList" columns="!v.mycolumns" hideCheckboxColumn="true" />
</aura:component>
//controller
(
init : function(component, event, helper)
helper.fetchContacts(component, event, helper);
)
Helper:
(
fetchContacts: function(component, event)
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'firstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'lastname',
type: 'text'
]);
var action = component.get("c.fetchCons");
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
var records = response.getReturnValue();
component.set("v.consList", records);
);
$A.enqueueAction(action);
)
Output:
Apex controller:
public class DisplayconsClass
@AuraEnabled
public static List <contact> fetchCons()
return [ SELECT firstName, lastname FROM contact LIMIT 10 ];
lightning-aura-components javascript datatable
New contributor
add a comment |
<aura:component controller="DisplayconsClass">
<aura:attribute type="Contact[]" name="consList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="!this" action="!c.init"/>
<lightning:datatable keyField="id" data="!v.consList" columns="!v.mycolumns" hideCheckboxColumn="true" />
</aura:component>
//controller
(
init : function(component, event, helper)
helper.fetchContacts(component, event, helper);
)
Helper:
(
fetchContacts: function(component, event)
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'firstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'lastname',
type: 'text'
]);
var action = component.get("c.fetchCons");
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
var records = response.getReturnValue();
component.set("v.consList", records);
);
$A.enqueueAction(action);
)
Output:
Apex controller:
public class DisplayconsClass
@AuraEnabled
public static List <contact> fetchCons()
return [ SELECT firstName, lastname FROM contact LIMIT 10 ];
lightning-aura-components javascript datatable
New contributor
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52
add a comment |
<aura:component controller="DisplayconsClass">
<aura:attribute type="Contact[]" name="consList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="!this" action="!c.init"/>
<lightning:datatable keyField="id" data="!v.consList" columns="!v.mycolumns" hideCheckboxColumn="true" />
</aura:component>
//controller
(
init : function(component, event, helper)
helper.fetchContacts(component, event, helper);
)
Helper:
(
fetchContacts: function(component, event)
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'firstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'lastname',
type: 'text'
]);
var action = component.get("c.fetchCons");
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
var records = response.getReturnValue();
component.set("v.consList", records);
);
$A.enqueueAction(action);
)
Output:
Apex controller:
public class DisplayconsClass
@AuraEnabled
public static List <contact> fetchCons()
return [ SELECT firstName, lastname FROM contact LIMIT 10 ];
lightning-aura-components javascript datatable
New contributor
<aura:component controller="DisplayconsClass">
<aura:attribute type="Contact[]" name="consList"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="!this" action="!c.init"/>
<lightning:datatable keyField="id" data="!v.consList" columns="!v.mycolumns" hideCheckboxColumn="true" />
</aura:component>
//controller
(
init : function(component, event, helper)
helper.fetchContacts(component, event, helper);
)
Helper:
(
fetchContacts: function(component, event)
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'firstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'lastname',
type: 'text'
]);
var action = component.get("c.fetchCons");
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
var records = response.getReturnValue();
component.set("v.consList", records);
);
$A.enqueueAction(action);
)
Output:
Apex controller:
public class DisplayconsClass
@AuraEnabled
public static List <contact> fetchCons()
return [ SELECT firstName, lastname FROM contact LIMIT 10 ];
lightning-aura-components javascript datatable
lightning-aura-components javascript datatable
New contributor
New contributor
edited Apr 28 at 23:51
glls
12k72253
12k72253
New contributor
asked Apr 28 at 20:26
NishanthNishanth
62
62
New contributor
New contributor
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52
add a comment |
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52
add a comment |
2 Answers
2
active
oldest
votes
Field names are cAsE-sEnSiTiVe. It should be FirstName
and LastName
, not firstName
and lastname
. You must use the case from their API name, not however you've written it in your Apex code query.
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'FirstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'LastName',
type: 'text'
]);
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
add a comment |
Change the apex controller to the following:
public class DisplayconsClass
@AuraEnabled
public static List fetchCons()
List listToReturn = new List();
List tempList = SELECT firstName, lastname FROM contact LIMIT 10 ];for(Contact temp : tempList)
CotactWrapper tempWrap = new ContactWrapper();
tempWrap.firstName = temp.firstName;
tempWrap.lastname = temp.lastname;
listToReturn.add(tempWrap);
return ListToReturn;
public class ContactWrapper
@AuraEnabled public String firstName;
@AuraEnabled public String lastname;
In your JavaScript controller change to the following code:
if (state === "SUCCESS")
var records = response.getReturnValue();
var toJson = JSON.stringify(records);
component.set("v.consList", toJson);
Tbh I'm not sure whether it's JSON.stringify or JSON.parse so just try both.
- in the component change the attribute:
<aura:attribute type="Object" name="consList"/>
or Object[]
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
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
);
);
Nishanth is a new contributor. Be nice, and check out our Code of Conduct.
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%2f260352%2fcannot-populate-data-in-lightning-data-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Field names are cAsE-sEnSiTiVe. It should be FirstName
and LastName
, not firstName
and lastname
. You must use the case from their API name, not however you've written it in your Apex code query.
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'FirstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'LastName',
type: 'text'
]);
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
add a comment |
Field names are cAsE-sEnSiTiVe. It should be FirstName
and LastName
, not firstName
and lastname
. You must use the case from their API name, not however you've written it in your Apex code query.
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'FirstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'LastName',
type: 'text'
]);
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
add a comment |
Field names are cAsE-sEnSiTiVe. It should be FirstName
and LastName
, not firstName
and lastname
. You must use the case from their API name, not however you've written it in your Apex code query.
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'FirstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'LastName',
type: 'text'
]);
Field names are cAsE-sEnSiTiVe. It should be FirstName
and LastName
, not firstName
and lastname
. You must use the case from their API name, not however you've written it in your Apex code query.
component.set('v.mycolumns', [
label: 'First Name',
fieldName: 'FirstName',
type: 'text'
,
label: 'Last Name',
fieldName: 'LastName',
type: 'text'
]);
answered Apr 28 at 22:43
sfdcfoxsfdcfox
268k13213462
268k13213462
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
add a comment |
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
Thank you so much .. it worked.
– Nishanth
Apr 28 at 22:50
add a comment |
Change the apex controller to the following:
public class DisplayconsClass
@AuraEnabled
public static List fetchCons()
List listToReturn = new List();
List tempList = SELECT firstName, lastname FROM contact LIMIT 10 ];for(Contact temp : tempList)
CotactWrapper tempWrap = new ContactWrapper();
tempWrap.firstName = temp.firstName;
tempWrap.lastname = temp.lastname;
listToReturn.add(tempWrap);
return ListToReturn;
public class ContactWrapper
@AuraEnabled public String firstName;
@AuraEnabled public String lastname;
In your JavaScript controller change to the following code:
if (state === "SUCCESS")
var records = response.getReturnValue();
var toJson = JSON.stringify(records);
component.set("v.consList", toJson);
Tbh I'm not sure whether it's JSON.stringify or JSON.parse so just try both.
- in the component change the attribute:
<aura:attribute type="Object" name="consList"/>
or Object[]
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
add a comment |
Change the apex controller to the following:
public class DisplayconsClass
@AuraEnabled
public static List fetchCons()
List listToReturn = new List();
List tempList = SELECT firstName, lastname FROM contact LIMIT 10 ];for(Contact temp : tempList)
CotactWrapper tempWrap = new ContactWrapper();
tempWrap.firstName = temp.firstName;
tempWrap.lastname = temp.lastname;
listToReturn.add(tempWrap);
return ListToReturn;
public class ContactWrapper
@AuraEnabled public String firstName;
@AuraEnabled public String lastname;
In your JavaScript controller change to the following code:
if (state === "SUCCESS")
var records = response.getReturnValue();
var toJson = JSON.stringify(records);
component.set("v.consList", toJson);
Tbh I'm not sure whether it's JSON.stringify or JSON.parse so just try both.
- in the component change the attribute:
<aura:attribute type="Object" name="consList"/>
or Object[]
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
add a comment |
Change the apex controller to the following:
public class DisplayconsClass
@AuraEnabled
public static List fetchCons()
List listToReturn = new List();
List tempList = SELECT firstName, lastname FROM contact LIMIT 10 ];for(Contact temp : tempList)
CotactWrapper tempWrap = new ContactWrapper();
tempWrap.firstName = temp.firstName;
tempWrap.lastname = temp.lastname;
listToReturn.add(tempWrap);
return ListToReturn;
public class ContactWrapper
@AuraEnabled public String firstName;
@AuraEnabled public String lastname;
In your JavaScript controller change to the following code:
if (state === "SUCCESS")
var records = response.getReturnValue();
var toJson = JSON.stringify(records);
component.set("v.consList", toJson);
Tbh I'm not sure whether it's JSON.stringify or JSON.parse so just try both.
- in the component change the attribute:
<aura:attribute type="Object" name="consList"/>
or Object[]
Change the apex controller to the following:
public class DisplayconsClass
@AuraEnabled
public static List fetchCons()
List listToReturn = new List();
List tempList = SELECT firstName, lastname FROM contact LIMIT 10 ];for(Contact temp : tempList)
CotactWrapper tempWrap = new ContactWrapper();
tempWrap.firstName = temp.firstName;
tempWrap.lastname = temp.lastname;
listToReturn.add(tempWrap);
return ListToReturn;
public class ContactWrapper
@AuraEnabled public String firstName;
@AuraEnabled public String lastname;
In your JavaScript controller change to the following code:
if (state === "SUCCESS")
var records = response.getReturnValue();
var toJson = JSON.stringify(records);
component.set("v.consList", toJson);
Tbh I'm not sure whether it's JSON.stringify or JSON.parse so just try both.
- in the component change the attribute:
<aura:attribute type="Object" name="consList"/>
or Object[]
edited Apr 28 at 22:47
answered Apr 28 at 22:44
DerminalDerminal
1116
1116
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
add a comment |
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.
– sfdcfox
Apr 28 at 22:45
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
@sfdcfox I think you have to. That the way to match between the fieldName of the column to the attribute of the wrapper class, no?
– Derminal
Apr 28 at 22:51
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
The Aura framework takes care of converting your wrapper to native objects in JavaScript automatically. The only reason you'd need JSON.parse is if you returned a JSON string originally.
– sfdcfox
Apr 28 at 22:53
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.
– Derminal
Apr 28 at 22:54
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
It was the case sensitive issue and thank you @sfdcfox
– Nishanth
4 hours ago
add a comment |
Nishanth is a new contributor. Be nice, and check out our Code of Conduct.
Nishanth is a new contributor. Be nice, and check out our Code of Conduct.
Nishanth is a new contributor. Be nice, and check out our Code of Conduct.
Nishanth is a new contributor. Be nice, and check out our Code of Conduct.
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%2f260352%2fcannot-populate-data-in-lightning-data-table%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
Hi Nishanth - can you please add the Apex controller code as well? Also, it would be helpful to make the code more readable (less spacing and less newlines)
– Brian Miller
Apr 28 at 20:29
@BrianMiller: Added the apex controller.
– Nishanth
Apr 28 at 20:52