I tried to pass integer attribute to controller but it didn't pass. Here is the code that i used.
Component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" controller="BACSPaymentManagerController">
<aura:attribute name="NextNDays" type="Integer" />
<aura:attribute name="BACSConfirmation" type="Boolean" default="false"/>
<aura:attribute name="paymentRecords" type="List" />
<aura:attribute name="selectedRows" type="List" />
<aura:attribute name="rowsSelected" type="List" />
<aura:attribute name="columns" type="List" />
<lightning:card title="BACS" iconName="standard:file">
<aura:set attribute="actions">
<lightning:input type="Number" label="Next N days" value="{!v.NextNDays}" />
<lightning:button class="slds-button_brand" label="Fetch Payments" onclick="{!c.fetchPayments}" />
</aura:set>
<div class="slds-col slds-size_12-of-12 slds-p-around_xx-small">
<lightning:datatable data="{!v.paymentRecords}" columns="{!v.columns}" keyField="Id"
selectedRows="{!v.selectedRows}" onrowselection="{!c.updateSelectedRows}"/>
</div>
</lightning:card>
</aura:component>
Controller
({
fetchPayments : function(component, event, helper) {
helper.fetchPayments(component, event);
})
Helper
({
fetchPayments : function(component, event) {
var integerNextNDays = component.get("v.NextNDays");
var action = component.get("c.getPayments");
action.setParam({"nextNDays": integerNextNDays});
action.setCallback(this, function(response){
console.log(response.getState());
if(response.getState() == 'SUCCESS'){
if(response.getReturnValue() != undefined){
component.set("v.columns",[
{label:'Id', fieldName:'Id',type:'text'},
{label:'Name', fieldName:'Name',type:'text',sortable:'true'},
{label:'Amount', fieldName:'Amount_Paid__c', type:'currency',sortable:'true', typeAttribute:{currencyCode:'GBP'}},
]);
component.set("v.paymentRecords", response.getReturnValue());
}
}
});
$A.enqueueAction(action);
}
})
Apex Controller
public class BACSPaymentManagerController {
@AuraEnabled
public static List<Payment__c> getPayments(Integer nextNDays){
if(nextNDays>0){
try {
Date dt = system.today() + nextNDays;
List<Payment__c> allFilteredPayments = [SELECT Amount_Paid__c,Name,Name__c,Account_Number__c,Sort_Code__c,Contact__r.Client_Reference_BACS__c,Date_Due__c FROM Payment__c WHERE Payment_Type__c = 'BACS' AND Confirm_Payment__c = false AND Date_Due__c >= :system.today() AND Date_Due__c <=:dt];
return allFilteredPayments;
}
catch (Exception e) {
// "Convert" the exception into an AuraHandledException
throw new AuraHandledException('Darn it! Something went wrong: '
+ e.getMessage());
}
}
else
return [SELECT Amount_Paid__c,Name,Name__c,Account_Number__c,Sort_Code__c,Contact__r.Client_Reference_BACS__c,Date_Due__c FROM Payment__c WHERE Payment_Type__c = 'BACS' AND Confirm_Payment__c = false];
}
}
Is there anything that i missed? Thanks