function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SUJAY GANGULYSUJAY GANGULY 

getting error in NEXT lightning button

I am creating a drop-down list in lightning which show 2 lists of events depends on the drop-down list today, PastDay and future value. I am also creating two buttons Next and Previous. which go to the next 2 list of the events and also come back. But im getting an error when im clicking on the Next button. My code and screenshots are below. please tell me how I  solved it.

Drop-down pagefacing error when click on Next button



My Fisrt Component:
<aura:component controller="EventdayClass">
    
    <aura:attribute name="event" type="Event[]"/>
    <aura:attribute name="eventchange" type="String[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    
    <aura:attribute name="offset" type="integer"/>
    <aura:attribute name="next" type="boolean"/>
    <aura:attribute name="prev" type="boolean"/>
    
    <lightning:button label="Next" onclick="{!c.next}"/>
    <lightning:button label="Previous" onclick="{!c.prev}"/>
    
     <ui:inputSelect aura:id="levels" change="{!c.onSelectChange}">
        <aura:iteration items="{!v.eventchange}" var="level">
            <ui:inputSelectOption text="{!level}" label="{!level}"/>
        </aura:iteration>
    </ui:inputSelect>
                <aura:iteration items="{!v.event}" var="items">
                    <c:EventDetails eventDetailsList="{!items}"/>
                   </aura:iteration>
    
</aura:component>

Controller class for this component:
({
    
    doInit: function(component,event,helper){
        var eventname=["Today","PastDay","Future"];
        component.set("v.eventchange",eventname);
        
        var action= component.get("c.daycal");
        action.setParams({"DayName":component.find('levels').get("v.value")});
          
        action.setCallback(this,function(response){
            component.set("v.event",response.getReturnValue())
        });
        
        
        $A.enqueueAction(action);


    },
    onSelectChange : function(component, event, helper) {
        var action= component.get("c.daycal");
        action.setParams({"DayName":component.find('levels').get("v.value")});
          
        action.setCallback(this,function(response){
            component.set("v.event",response.getReturnValue())
        });
        //var selected=  component.find('levels').get("v.value");
        
        
        $A.enqueueAction(action);

                     
    },
    
    next:function(component,event,helper){
        var nxt= ture;
        var prv=false;
        var offset=component.get("v.offset");
       // helper.next(component,nxt,prv,offset);
       
    },
    prev:function(component,event,helper){
        var nxt= false;
        var prv=ture;
        var offset=component.get("v.offset");
        helper.next(component,nxt,prv,offset);
    }
    
})

Helper controller class:
({
    next : function(component,nxt,offset) {
        var total= total||0;
         var action= component.get("c.getbtnlist");
        
        action.setParams({
            "next" : next          
        });
         action.setCallback(this,function(response){
             var result = res.getReturnValue();
              cmp.set('v.total',result.totalcount);
             // cmp.set('v.accounts',result.acc);
              cmp.set('v.next',result.hasnext);
             // cmp.set('v.prev',result.hasprev);
             
           // component.set("v.event",response.getReturnValue());
           // component.set('v.next',result.hasnext.hasnext);
        });
       
        
        
        $A.enqueueAction(action);

        
        
    },
    prev : function(component,nxt,total) {
        var total= total ||0;
         var action= component.get("c.getbtnlist");
        
        action.setParams({
            "prev" : prev          
        });
        action.setCallback(this,function(response){
             var result = res.getReturnValue();
              cmp.set('v.total',result.totalcount);
            
             
             cmp.set('v.prev',result.hasprev);
             
           // component.set("v.event",response.getReturnValue());
           // component.set('v.next',result.hasnext.hasnext);
        
         action.setCallback(this,function(response){
            component.set("v.event",response.getReturnValue());
            component.set('v.prev',result.hasprev);
        });
       
        
        
        $A.enqueueAction(action);

        
        
    }
})

Apex class:
public class EventdayClass {
    
    @AuraEnabled
    public static List<Event> daycal(String DayName){
        if(DayName=='Future'){
            return[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime=:System.today() and StartDateTime!=null limit 2];
        
        }
        else if(DayName=='PastDay'){
            return[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime<:System.today() and StartDateTime!=null limit 2];
        }
        else if(DayName=='Today'){
            return[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime>:System.today() and StartDateTime!=null limit 2];
        }
        else{
            return[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime=:System.today() and StartDateTime!=null limit 2];
        }
        
    }
    
    
    //
    //
    //
    
   @AuraEnabled
     public list<event> evn;
      
     @AuraEnabled
     public integer totalcount;
      
     
     @AuraEnabled
     public boolean hasprev;
      
     @AuraEnabled
     public boolean hasnext;
    
    private static integer pagesize=2;
    private static integer total;
   @AuraEnabled
    public static EventdayClass getbtnlist(Boolean next,Boolean prev,decimal off){
        total = (integer)off;
        System.debug('total'+total);
        List<Event> EventList= new List<Event>();
        integer listlenght=[select count() from event where StartDateTime!=null];
        if(next==true && prev==false && (total+pagesize<=listlenght)){
            total=total+pagesize;
            System.debug('total next'+total);
            EventList=[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime!=null limit:pagesize OFFSET:total];
            System.debug('EventList Next'+EventList);
            
        }
        else if(prev==true && total>0){
            total=total-pagesize;
            System.debug('total prev'+total);
            EventList=[select id,Subject,StartDateTime,WhoId,WhatId,Who.Name,What.Name from Event where StartDateTime!=null limit:pagesize OFFSET:total];
            System.debug('EventList prev'+EventList);
        }
        
        EventdayClass ec= new EventdayClass();
        ec.evn=EventList;
        System.debug('ec.evn'+ec.evn);
        ec.totalcount=total;
        System.debug('ec.totalcount'+ec.totalcount);
        ec.hasprev = hasprev(total);   
        System.debug('ec.hasprev'+ec.hasprev);
        ec.hasnext = hasnxt(total,listlenght,pagesize);
        System.debug('ec.hasnext'+ec.hasnext);
        return ec;
       
        
    }
    private static boolean hasprev(integer off){
            if(off>0)
                return false;
            return true; 
        }
        private static boolean hasnxt(integer off,integer li,integer ps){
        if(off+ps<li)
            return false;
        return true;
        }
        
          
    
      
  }
child component that i call in parent componenet:

<aura:component >
    
    <aura:attribute name="eventDetailsList" type="Event"/>
    
    
    
    
   <aura:iteration items="{!v.eventDetailsList}" var="items">
                    <c:Evenlistbtnnn eventbutton="{!items}"/>
   </aura:iteration>
            
                            
        
    
    
    
         
          

   
        
  <table>  
      
                {!v.eventDetailsList.Subject}
               
               <a href="{!'#/sObject/'+v.eventDetailsList.Who.Id+'/view'}">{!v.eventDetailsList.Who.Name}</a>
                <a href="{!'#/sObject/'+v.eventDetailsList.What.Id+'/view'}">{!v.eventDetailsList.What.Name}</a>
                {!v.eventDetailsList.StartDateTime}

             
    </table>
    
    
  
    <!--Next Button-->
    <!--a href="{!'#/sObject/'+v.eventDetailsList.Id+'/view'}">{!v.eventDetailsList.Subject}</a>
    <a href="{!'#/sObject/'+v.eventDetailsList.Who.Id+'/view'}">{!v.eventDetailsList.Who.Name}</a>
    <a href="{!'#/sObject/'+v.eventDetailsList.What.Id+'/view'}">{!v.eventDetailsList.What.Name}</a>
    <a href="{!'#/sObject/'+v.eventDetailsList.RecurrenceStartDateTime.Id+'/view'}">{!v.eventDetailsList.RecurrenceStartDateTime}</a-->
    
    <aura:iteration items="{!v.eventDetailsList}" var="items">
                    <c:Evenlistbtn eventbutton="{!items}"/>
    </aura:iteration>
    
    
    
</aura:component>
Nithesh NNithesh N
Hi, It is just a typo mistake.
Replace "ture" with "true". 
 
next:function(component,event,helper){
        var nxt= true;
        var prv=false;
        var offset=component.get("v.offset");
       // helper.next(component,nxt,prv,offset);
       
    },
prev:function(component,event,helper){
        var nxt= false;
        var prv=true;
        var offset=component.get("v.offset");
        helper.next(component,nxt,prv,offset);
    }


It will work just fine.

Please Mark this post as Best Answer if it solves your query.

Best,
Nithesh. 

 
SUJAY GANGULYSUJAY GANGULY
Error not showing now but next button not working also Thanks, Sujay Ganguly skype: sujay.801389@gmail.com
Nithesh NNithesh N
Looks like the helper method call is commented...check it.
next:function(component,event,helper){
        var nxt= true;
        var prv=false;
        var offset=component.get("v.offset");
       // helper.next(component,nxt,prv,offset);
       
    }

uncomment the
helper.next(component,nxt,prv,offset);

Please Mark this post as Best Answer if it solves your query.

Best,
Nithesh.