You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to display record based on selected dates?
Hi, i am having Object named Research_Paper__c . How to dispay records depending on selected dates.. For example,after clicking show button, i want to display name of Research Papers whose publication date is between 1/8/2020 and 14/8/2020.. How to do it in Lightning?
Let me know if it helps
Please follow the below steps:
- Create a lightning componet with three attributes:
- Start Date
- End Date
- List to hold records between start date and end date
- Add two input type of Date in component and one button called Submit
- Now on click of this Submit button, call your apex method that will take these two dates as input and return the records between these dates via SOQL.
- Store this result in the list
- Display the list in component.
Let me know if you need any other help on this.Thanks,
Abhishek Bansal.
<aura:component controller="Accountobjcontroller" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
<aura:attribute name="accList" type="Account[]"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="fromDate" type="date"/>
<aura:attribute name="toDate" type="date"/>
<aura:handler name="init" value="{! this }" action="{! c.doinit }"/>
<lightning:input name="date1" label="From Date" type="date" value="{!v.fromDate}"/>
<lightning:input name="date2" label="To Date" type="date" value="{!v.toDate}"/>
<lightning:button variant="brand" label="Get Accounts" iconName="utility:search" onclick="{!c.getAcconts}"/>
<div style="height: 300px">
<lightning:datatable
keyField="id"
data="{! v.accList }"
columns="{! v.columns }"
hideCheckboxColumn="true"/>
</div>
</aura:component>
({
doinit : function(cmp, event, helper){
cmp.set('v.columns', [
{label: 'Account name', fieldName: 'Name', type: 'text'},
{label: 'Rating', fieldName: 'Rating', type: 'text'},
{label: 'Type', fieldName: 'Type', type: 'text'},
{label: 'SLA', fieldName: 'SLA__c', type: 'text'},
{label: 'Created Date', fieldName: 'CreatedDate', type: 'date'}
]);
},
getAcconts : function(cmp, event, helper) {
console.log('In Controller');
helper.getAccountHelper(cmp);
}
})
helper.js
({
getAccountHelper : function(cmp) {
var action=cmp.get('c.getAccountList');
var frDate=cmp.get('v.fromDate');
var trDate=cmp.get('v.toDate');
action.setParams({fDate : frDate, tDate : trDate});
action.setCallback(this, function(response){
var state=response.getState();
if(state=='SUCCESS'){
cmp.set('v.accList', response.getReturnValue());
}
else{
console.log('No records found');
}
});
$A.enqueueAction(action);
}
})
Apex Controller
@auraEnabled
public static List<Account> getAccountList(date fDate, date tDate){
system.debug('From Date: '+fDate);
system.debug('To Date: '+tDate);
List<Account> accList=new List<Account>();
accList=[select id, name, rating, type, SLA__c, createdDate from Account where
createdDate>=:fDate and createdDate<=:tDate];
if(!accList.isEmpty()){
return accList;
}
else{
return null;
}
}
}