You need to sign in to do that
Don't have an account?
Bobination
I am having a problem with my list inside lightning datatable
I am trying to list all my related contracts to an agency X..
Here is my code:
ContractsList component
<aura:component controller="ContractsController"
implements="flexipage:availableForRecordHome,force:hasRecordId"
access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Agency" type="ibrahimdevo__Agency__c" />
<aura:attribute name="Contracts" type="ibrahimdevo__Contract__c" />
<aura:attribute name="Columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.myAction}" />
<force:recordData aura:id="agencyRecord"
recordId="{!v.recordId}"
targetFields="{!v.Agency}"
layoutType="FULL"
/>
<lightning:card iconName="standard:event" title="{! 'Liste de contrats pour ' + v.Agency.ibrahimdevo__agency_name__c}">
<lightning:datatable data="{! v.Contracts}" columns="{! v.Columns }" keyField="Id" hideCheckboxColumn="true"/>
</lightning:card>
ContractsListController
({
myAction : function(component, event, helper) {
var action = component.get("c.getContracts");
component.set("v.Columns", [
{label:"Contract Code", fieldName:"ContractCode", type:"text"},
{label:"Valid From", fieldName:"ValidFrom", type:"Date"},
{label:"Valid To", fieldName:"ValidTo", type:"Date"},
{label:"Signed date", fieldName:"SignedDate", type:"Date"}
]);
action.setParams({
recordID: component.get("v.recordId")
});
action.setCallback(this, function(data){
component.set("v.Contracts", data.getReturnValue());
});
$A.enqueueAction(action);
}
})
ContractsController
@AuraEnabled
public static List<ibrahimdevo__Contract__c> getContracts(Id recordId) {
return[Select Name, ibrahimdevo__contract_code__c, ibrahimdevo__date_signed__c,
ibrahimdevo__valid_from__c, ibrahimdevo__valid_to__c, ibrahimdevo__details__c
From ibrahimdevo__Contract__c Where ibrahimdevo__agency_id__r.id = :recordId];
}
i am not getting any errors but the list doesn't show up :(
thanks in advance
Here is my code:
ContractsList component
<aura:component controller="ContractsController"
implements="flexipage:availableForRecordHome,force:hasRecordId"
access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Agency" type="ibrahimdevo__Agency__c" />
<aura:attribute name="Contracts" type="ibrahimdevo__Contract__c" />
<aura:attribute name="Columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.myAction}" />
<force:recordData aura:id="agencyRecord"
recordId="{!v.recordId}"
targetFields="{!v.Agency}"
layoutType="FULL"
/>
<lightning:card iconName="standard:event" title="{! 'Liste de contrats pour ' + v.Agency.ibrahimdevo__agency_name__c}">
<lightning:datatable data="{! v.Contracts}" columns="{! v.Columns }" keyField="Id" hideCheckboxColumn="true"/>
</lightning:card>
ContractsListController
({
myAction : function(component, event, helper) {
var action = component.get("c.getContracts");
component.set("v.Columns", [
{label:"Contract Code", fieldName:"ContractCode", type:"text"},
{label:"Valid From", fieldName:"ValidFrom", type:"Date"},
{label:"Valid To", fieldName:"ValidTo", type:"Date"},
{label:"Signed date", fieldName:"SignedDate", type:"Date"}
]);
action.setParams({
recordID: component.get("v.recordId")
});
action.setCallback(this, function(data){
component.set("v.Contracts", data.getReturnValue());
});
$A.enqueueAction(action);
}
})
ContractsController
@AuraEnabled
public static List<ibrahimdevo__Contract__c> getContracts(Id recordId) {
return[Select Name, ibrahimdevo__contract_code__c, ibrahimdevo__date_signed__c,
ibrahimdevo__valid_from__c, ibrahimdevo__valid_to__c, ibrahimdevo__details__c
From ibrahimdevo__Contract__c Where ibrahimdevo__agency_id__r.id = :recordId];
}
i am not getting any errors but the list doesn't show up :(
thanks in advance
You have to refer the field name properly in Datatable Columns:
In the JS please include the Field Api Names properly in below line fieldname:
component.set("v.Columns", [
{label:"Contract Code", fieldName:"ibrahimdevo__contract_code__c", type:"text"},
{label:"Valid From", fieldName:"ibrahimdevo__valid_from__c", type:"Date"},
{label:"Valid To", fieldName:"ibrahimdevo__valid_to__c", type:"Date"},
{label:"Signed date", fieldName:"ibrahimdevo__date_signed__c", type:"Date"}
]);
Thanks,
Maharajan.C
All Answers
You have to refer the field name properly in Datatable Columns:
In the JS please include the Field Api Names properly in below line fieldname:
component.set("v.Columns", [
{label:"Contract Code", fieldName:"ibrahimdevo__contract_code__c", type:"text"},
{label:"Valid From", fieldName:"ibrahimdevo__valid_from__c", type:"Date"},
{label:"Valid To", fieldName:"ibrahimdevo__valid_to__c", type:"Date"},
{label:"Signed date", fieldName:"ibrahimdevo__date_signed__c", type:"Date"}
]);
Thanks,
Maharajan.C
is it the right way to pass record Id ?
action.setParams({
recordID: component.get("v.recordId") ==> recordId: component.get("v.recordId")
});
The param should be same as metioned in Class.