Friday, January 17, 2014

Pagination

===========VFPage=============
<apex:page sidebar="false" standardController="Condidate__c" extensions="pagination2" >
  <apex:sectionHeader title="Pagintion" subtitle="Condidate"/>
    <apex:form id="fm">
       <apex:pageBlock id="pb" mode="inlineEdit">
          <apex:pageBlockSection id="ps" title="Condidate Records" columns="1" >
            <apex:pageBlockSectionItem >RecordsName</apex:pageBlockSectionItem>
                <apex:repeat value="{!mapCon[selectpage]}" var="A" >
                    <apex:outputlabel value="{!A.Name}"></apex:outputlabel>
               </apex:repeat>
               <apex:selectList value="{!Selectpage}" size="1">
                   <apex:selectOptions value="{!pageOption}"></apex:selectOptions>
               <apex:actionSupport event="onchange" action="{!NextPage}" />
             
             </apex:selectList>
          </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>
=============Controller==================
public with sharing class pagination2 {

    public Integer selectpage{set;get;}
   
    public Integer RecordsPerPage{set;get;}
   
    public Map<Integer,List<Condidate__c>> mapCon{set;get;}
   
    public List<selectOption> pageOption{set;get;}  

    public pagination2(ApexPages.StandardController controller) {
         
          mapCon=new map<Integer,List<condidate__c>>();
         
          RecordsPerPage=4;
         
          selectpage=1;
         
          List<Condidate__c> ConList=[select id, name from condidate__c];
             
              if(Conlist.size()>0){
                   Integer Total_Pages= conList.size()/ RecordsPerPage;
                   if(math.mod(conList.size(), RecordsPerPage)>0){
                        Total_Pages+=1;
                   }
                   pageOption=new list<selectoption>();
                 
                   Integer firstpage=0;
                 
                   Integer lastpage=RecordsPerPage;
                 
                   for(Integer i=0;i<Total_Pages;i++){
                 
                      Integer counter=i+1;
                     
                      pageoption.add(new selectoption(counter+'',counter+''));
                     
                      List<Condidate__c> listcon=new list<Condidate__c>();
                     
                      for(Integer j=firstpage;j<lastpage;j++){
                     
                         try{
                             listcon.add( conList[j]);
                         }
                         catch(Exception e){
                         }  
                      }
                     
                     firstpage=lastpage;
                     lastpage=RecordsPerPage*(i+2);
                     mapCon.put(counter,listcon);
                       
                   }
                 
              }
    }
  public void nextpage(){}
}

No comments:

Post a Comment