The problem of error is resolved but whenever I scroll my datatable, the loadMoreData function only returns the next 10 records and not executes further i.e even after scrolling only 20 records are visible
loadMoreData:function(component,event,helper){ event.getSource().set("v.isLoading", true); component.set('v.loadMoreStatus', 'Loading....'); var totalNumberofRows=component.get('v.totalNumberOfRows'); var currentData=component.get("v.data"); var counts = component.get("v.currentCount"); var recordLimit=component.get("v.initialRows"); if(component.get('v.data').length>=component.get('v.totalNumberOfRows')){ //console.log("inside if"); component.set('v.enableInfiniteLoading', false); component.set('v.loadMoreStatus', 'No more data to load'); }else{ var action=component.get("c.fetchRecordData"); action.setParams({ recordLimit: recordLimit, offSetCount: counts }); action.setCallback(this,function(response){ var state=response.getState(); console.log(state);
if(state === "SUCCESS"){ var newData=response.getReturnValue(); console.log(newData); var data=currentData.concat(newData); component.set("v.data",data); counts=counts+recordLimit; component.set("v.currentCount",counts); component.set('v.enableInfiniteLoading', true); } }); $A.enqueueAction(action); } }
// apex function @AuraEnabled public static List<Student__c> fetchRecordData(Integer recordLimit,Integer offSetCount){ Integer inLimit=Integer.valueOf(recordLimit); Integer inOffSet=Integer.valueOf(offSetCount); System.debug([SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet]); return [SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet]; }
Can you elloborate more on this?
Thanks,
loadMoreData:function(component,event,helper){
event.getSource().set("v.isLoading", true);
component.set('v.loadMoreStatus', 'Loading....');
var totalNumberofRows=component.get('v.totalNumberOfRows');
var currentData=component.get("v.data");
var counts = component.get("v.currentCount");
var recordLimit=component.get("v.initialRows");
if(component.get('v.data').length>=component.get('v.totalNumberOfRows')){
//console.log("inside if");
component.set('v.enableInfiniteLoading', false);
component.set('v.loadMoreStatus', 'No more data to load');
}else{
var action=component.get("c.fetchRecordData");
action.setParams({
recordLimit: recordLimit,
offSetCount: counts
});
action.setCallback(this,function(response){
var state=response.getState();
console.log(state);
if(state === "SUCCESS"){
var newData=response.getReturnValue();
console.log(newData);
var data=currentData.concat(newData);
component.set("v.data",data);
counts=counts+recordLimit;
component.set("v.currentCount",counts);
component.set('v.enableInfiniteLoading', true);
}
});
$A.enqueueAction(action);
}
}
// apex function
@AuraEnabled
public static List<Student__c> fetchRecordData(Integer recordLimit,Integer offSetCount){
Integer inLimit=Integer.valueOf(recordLimit);
Integer inOffSet=Integer.valueOf(offSetCount);
System.debug([SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet]);
return [SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet];
}