<apex:page standardcontroller="Account" extensions="MyPage">
<apex:form >
<apex:pageBlock >
<apex:commandButton value="New Account" action="https://c.ap1.visual.force.com/apex/AccountView"/>
<apex:datatable value="{!lstAccount}" var="c" id="idDt" cellPadding="8" border="0" >
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputField value="{!c.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Phone</apex:facet>
<apex:outputField value="{!c.phone}" />
</apex:column>
</apex:dataTable>
<apex:commandButton value="First" action="{!goFirst}" disabled="{!disableF}" />
<apex:commandButton value="Prev" action="{!goPrev}" disabled="{!disableP}" />
<apex:commandButton value="Next" action="{!goNext}" disabled="{!disableN}"/>
<apex:commandButton value="Last" action="{!goLast}" disabled="{!disableL}" />
<apex:selectList size="1" value="{!pageNumber}" >
<apex:selectOptions value="{!PNumber}"/>
</apex:selectList> of {!totalpage} <apex:commandButton value="Go" action="{!toJump}" />
</apex:pageBlock>
</apex:form>
</apex:page>
-----------------------------------------------------------------------------
------------------------------------------------------------------------------
public class MyPage {
ApexPages.StandardController con{get;set;}
public List<Account> lstaccount{get;set;}
public Integer pageNumber{get;set;}
public Integer pageRows{get;set;}
public Integer totalPage{get;set;}
Public AggregateResult[] result{get;set;}
public Integer allPage{get;set;}
public Boolean disableF{get;set;}
public Boolean disableP{get;set;}
public Boolean disableN{get;set;}
public Boolean disableL{get;set;}
public MyPage(ApexPages.StandardController controller) {
con=controller;
pageRows=5;
pageNumber=1;
result=[select count(id)c from Account];
totalPage=Integer.valueOf(math.floor(Integer.valueof(result[0].get('c'))/pageRows)+(math.mod(Integer.valueof(result[0].get('c')),pageRows)>0?1:0));
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public List<Account> findRecord(Integer pageRows,Integer pageNumber)
{
Integer crossRecord=(pageNumber-1)*pageRows;
List<Account> lstAccount=[Select name,phone from Account order by name limit:pageRows offset:crossRecord];
return lstaccount;
}
public void goFirst()
{
pageNumber=1;
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public void goPrev()
{
pageNumber-=1;
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public void goNext()
{
pageNumber+=1;
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public void goLast()
{
pageNumber=totalpage;
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public void toJump()
{
pageNumber=Integer.valueOf(pageNumber);
lstAccount=findRecord(pageRows,pageNumber);
toVisible(pageNumber);
}
public void toVisible(Integer pageNumber)
{
if(pageNumber==1){
disableF=true;
disableP=true;
disableN=false;
disableL=false;}
if(pageNumber>1&& pageNumber<totalPage){
disableF=false;
disableP=false;
disableN=false;
disableL=false;}
if(pageNumber==totalPage){
disableF=false;
disableP=false;
disableN=true;
disableL=true;}
}
public List<SelectOption> getPNumber() {
List<SelectOption> options = new List<SelectOption>();
for(Integer i=1;i<=totalpage;i++){
options.add(new SelectOption(String.valueof(i),String.valueof(i)));
}
return options;
}
}
No comments:
Post a Comment