View

Wednesday, May 1, 2013

Apex Code : Pagging.............



Page Editor:
------------
<apex:page Controller="LeadCusControl" action="{!Search}" sidebar="false" >
<apex:form id="changeStatusForm">
        <apex:pageBlock id="pb1" >
        <apex:pageMessages />
        <table width="100%">
      <tr>
      <td align="left" ><apex:commandButton value="Prev"  action="{!Prev}" rendered="{!showprev}"  rerender="pb1"/></td>
       
          <td align="right"><apex:commandButton value="Next"  action="{!Next}" rendered="{!shownext}"  rerender="pb1"/></td>
      </tr>
      </table>
            <apex:pageBlockTable value="{!leads}" var="c" columns="7">
            <apex:column value="{!c.Name}"/>
            <apex:column value="{!c.Company}"/>
            <apex:column value="{!c.Title}"/>
            <apex:column headerValue="Recent Activity">
                  <apex:dataTable value="{!c.Tasks}" var="s" >
                      <apex:column value="{!s.subject}" style="border-bottom-color:transparent;" />
                  </apex:dataTable>
           </apex:column>
            <apex:column value="{!c.City}"/>
                        <apex:column headerValue="Action"  >
                        <a href="/00T/e?who_id={!c.id}&retURL=%2F{!c.id}">Next Activity </a>        
                        <a href="/{!c.id}/e?retURL=%2F{!c.id}" > / EditLead</a>
            </apex:column>
        </apex:pageBlockTable>
      <table width="100%">
      <tr>
      <td align="left" ><apex:commandButton value="Prev"  action="{!Prev}" rendered="{!showprev}"  rerender="pb1"/></td>
          <td align="Center"><b><apex:outputtext rendered="{!NOT(ISNULL(Leads))}"  value="{!LdList_Size}  records in Lead"/></b></td>
          <td align="right"><apex:commandButton value="Next"  action="{!Next}" rendered="{!shownext}"  rerender="pb1"/></td>
      </tr>
      </table>
</apex:pageBlock>    
</apex:form>
</apex:page>

Apex Class
------------------
public class LeadCusControl {
    List<Lead> LdList = new List<Lead>();
    List<Lead> LdList_Next = new List<Lead>();
    Integer next = 10, count = 10;
    boolean shownext, showprev;
   
    Public void Search()
    {
        try
        {
            LdList = [SELECT name,company,title,city,state,email,id, (SELECT subject FROM tasks order by lastmodifieddate desc limit 1) FROM lead];
            if(LdList.size()>count)
            {
                for(Integer i=0; i<count; i++)
                LdList_Next.add(LdList[i]);
                shownext = true;
            }
            else
            LdList_Next = LdList;
        }catch(Exception e){system.debug('Exception :'+e);}
    }
    Public Integer GetLdList_Size()
    {
        return LdList.size();
    }
     Public List<Lead> GetLeads()
    {
        return LdList_Next;
    }
    Public void Next()
    {
        try
        {
            showprev = true;
            LdList_Next.clear();
            Integer limit1 = 0;
   
            if(next+count < LdList.size())
                limit1 = next+count;
            else
            {
                limit1 = LdList.size();
                shownext = false;
            }
               
            for(Integer i=next; i<limit1; i++)
            LdList_Next.add(LdList[i]);
   
            Next+=count;
        }catch(Exception e){system.debug('Exception :'+e);}
    }
    Public void Prev()
    {
        try
        {
            shownext = true;
            LdList_Next.clear();
            Integer limit1 = 0;      
            if(next-(count+count) > 0)
                limit1 = next-count;
            else
            {
                limit1 = next-count;
                showprev = false;
            }
   
            for(Integer i=next-(count+count); i<limit1; i++)  
            LdList_Next.add(LdList[i]);
            Next-=count;
        }catch(Exception e){system.debug('Exception :'+e);}              
    }
   
    Public boolean getshownext(){return shownext;}
   
    Public boolean getshowprev(){return showprev;}
}

No comments:

Post a Comment

Share your Comments .............