Cannot populate data in lightning data tableLightning Event ModelCan I fire an application event from a...

Is it possible to Ready a spell to be cast just before the start of your next turn by having the trigger be an ally's attack?

Cannot populate data in lightning data table

Stateful vs non-stateful app

What's the polite way to say "I need to urinate"?

What is the strongest case that can be made in favour of the UK regaining some control over fishing policy after Brexit?

Was there a Viking Exchange as well as a Columbian one?

Why do computer-science majors learn calculus?

Phrase for the opposite of "foolproof"

Do generators produce a fixed load?

What are the spoon bit of a spoon and fork bit of a fork called?

Why didn't this hurt this character as badly?

Can I get candy for a Pokemon I haven't caught yet?

If Earth is tilted, why is Polaris always above the same spot?

Electric guitar: why such heavy pots?

Confusion about capacitors

Please, smoke with good manners

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

How to creep the reader out with what seems like a normal person?

Why was Germany not as successful as other Europeans in establishing overseas colonies?

gnu parallel how to use with ffmpeg

Bayesian Nash Equilibria in Battle of Sexes

Why does nature favour the Laplacian?

Python "triplet" dictionary?

Does jamais mean always or never in this context?



Cannot populate data in lightning data table


Lightning Event ModelCan I fire an application event from a Lightning callback function?Understanding Lightning interactions - How does Lightning component and controller (.js) calls apex class controller and interact with it?Automatically navigate to the contact page from Lightning Componentlightning:recordEditForm basically 'Dies' during random situationsLightning component is hang for first timeremove footer for lightning data tablelightning:conversationAgentSend not working, as well infinite loop posting multiple messageAre Address fields are restricted to save in LDS?Lightning Gantt Chart Development






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1
















<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:



enter image description here



Apex controller:



public class DisplayconsClass {

@AuraEnabled
public static List <contact> fetchCons() {

return [ SELECT firstName, lastname FROM contact LIMIT 10 ];

}

}









share|improve this question









New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
    3 hours ago











  • @BrianMiller: Added the apex controller.

    – Nishanth
    2 hours ago


















1
















<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:



enter image description here



Apex controller:



public class DisplayconsClass {

@AuraEnabled
public static List <contact> fetchCons() {

return [ SELECT firstName, lastname FROM contact LIMIT 10 ];

}

}









share|improve this question









New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
    3 hours ago











  • @BrianMiller: Added the apex controller.

    – Nishanth
    2 hours ago














1












1








1









<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:



enter image description here



Apex controller:



public class DisplayconsClass {

@AuraEnabled
public static List <contact> fetchCons() {

return [ SELECT firstName, lastname FROM contact LIMIT 10 ];

}

}









share|improve this question









New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













<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:



enter image description here



Apex controller:



public class DisplayconsClass {

@AuraEnabled
public static List <contact> fetchCons() {

return [ SELECT firstName, lastname FROM contact LIMIT 10 ];

}

}






lightning datatable






share|improve this question









New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago







Nishanth













New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









NishanthNishanth

62




62




New contributor




Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Nishanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • 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
    3 hours ago











  • @BrianMiller: Added the apex controller.

    – Nishanth
    2 hours ago



















  • 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
    3 hours ago











  • @BrianMiller: Added the apex controller.

    – Nishanth
    2 hours ago

















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
3 hours ago





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
3 hours ago













@BrianMiller: Added the apex controller.

– Nishanth
2 hours ago





@BrianMiller: Added the apex controller.

– Nishanth
2 hours ago










2 Answers
2






active

oldest

votes


















2














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'
}

]);





share|improve this answer
























  • Thank you so much .. it worked.

    – Nishanth
    59 mins ago



















0
















  1. 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;
    }


    }




  2. 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.




  1. in the component change the attribute:



<aura:attribute type="Object" name="consList"/>



or Object[]






share|improve this answer


























  • You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

    – sfdcfox
    1 hour ago













  • @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
    58 mins ago











  • 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
    55 mins ago











  • @sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

    – Derminal
    55 mins ago














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.










draft saved

draft discarded


















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









2














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'
}

]);





share|improve this answer
























  • Thank you so much .. it worked.

    – Nishanth
    59 mins ago
















2














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'
}

]);





share|improve this answer
























  • Thank you so much .. it worked.

    – Nishanth
    59 mins ago














2












2








2







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'
}

]);





share|improve this answer













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'
}

]);






share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









sfdcfoxsfdcfox

267k13213461




267k13213461













  • Thank you so much .. it worked.

    – Nishanth
    59 mins ago



















  • Thank you so much .. it worked.

    – Nishanth
    59 mins ago

















Thank you so much .. it worked.

– Nishanth
59 mins ago





Thank you so much .. it worked.

– Nishanth
59 mins ago













0
















  1. 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;
    }


    }




  2. 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.




  1. in the component change the attribute:



<aura:attribute type="Object" name="consList"/>



or Object[]






share|improve this answer


























  • You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

    – sfdcfox
    1 hour ago













  • @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
    58 mins ago











  • 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
    55 mins ago











  • @sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

    – Derminal
    55 mins ago


















0
















  1. 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;
    }


    }




  2. 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.




  1. in the component change the attribute:



<aura:attribute type="Object" name="consList"/>



or Object[]






share|improve this answer


























  • You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

    – sfdcfox
    1 hour ago













  • @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
    58 mins ago











  • 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
    55 mins ago











  • @sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

    – Derminal
    55 mins ago
















0












0








0









  1. 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;
    }


    }




  2. 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.




  1. in the component change the attribute:



<aura:attribute type="Object" name="consList"/>



or Object[]






share|improve this answer

















  1. 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;
    }


    }




  2. 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.




  1. in the component change the attribute:



<aura:attribute type="Object" name="consList"/>



or Object[]







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 1 hour ago









DerminalDerminal

1135




1135













  • You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

    – sfdcfox
    1 hour ago













  • @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
    58 mins ago











  • 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
    55 mins ago











  • @sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

    – Derminal
    55 mins ago





















  • You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

    – sfdcfox
    1 hour ago













  • @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
    58 mins ago











  • 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
    55 mins ago











  • @sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

    – Derminal
    55 mins ago



















You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

– sfdcfox
1 hour ago







You wouldn't use JSON.stringify or JSON.parse. The return value is already a list of objects.

– sfdcfox
1 hour ago















@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
58 mins ago





@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
58 mins ago













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
55 mins ago





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
55 mins ago













@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

– Derminal
55 mins ago







@sfdcfox Got your point, the problem was about case-sensitive. Thanks for your input.

– Derminal
55 mins ago












Nishanth is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

“%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

夢乃愛華...