You need to sign in to do that
Don't have an account?
Kiran Kumar 77
Pagination using Offset
Hi Iam trying to do paination using offset keyword next button is working but previous button in not working..
<apex:page controller="trpaginationoffsetContrller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ConList}" var="con">
<apex:column value="{!con.Name}"/>
<apex:column >
<table width="100%">
<apex:repeat value="{!ConList}" var="ContactSelec">
<tr><td>{!ContactSelec.FirstName}</td> <td>{!ContactSelec.LastName }</td></tr>
</apex:repeat>
</table>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="Previous" action="{!Previous}"/>
<apex:commandButton value="Next" action="{!Next}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------------------------------------------------------------------------------
public class trpaginationoffsetContrller {
public List<Contact> ConList {get;set;}
public Integer Counter = 0;
public trpaginationoffsetContrller(){
//ConList = new List<Contact>
ConList = [select Id, Name,FirstName, LastName from Contact ORDER BY name Limit 10 OFFSET 0];
}
public void Next(){
Counter ++;
//ConList = new List<Contact>
ConList = [select Id, Name,FirstName, LastName from contact ORDER BY name
Limit 10 OFFSET 10
];
update ConList;
}
public void Previous(){
counter --;
conList = [select Id, Name,FirstName, LastName from Contact ORDER BY name limit 50 OFFSET 10];
update ConList;
}
}
and can you help me Account Names diplay its related contacts only in VF page
<apex:page controller="trpaginationoffsetContrller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ConList}" var="con">
<apex:column value="{!con.Name}"/>
<apex:column >
<table width="100%">
<apex:repeat value="{!ConList}" var="ContactSelec">
<tr><td>{!ContactSelec.FirstName}</td> <td>{!ContactSelec.LastName }</td></tr>
</apex:repeat>
</table>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="Previous" action="{!Previous}"/>
<apex:commandButton value="Next" action="{!Next}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------------------------------------------------------------------------------
public class trpaginationoffsetContrller {
public List<Contact> ConList {get;set;}
public Integer Counter = 0;
public trpaginationoffsetContrller(){
//ConList = new List<Contact>
ConList = [select Id, Name,FirstName, LastName from Contact ORDER BY name Limit 10 OFFSET 0];
}
public void Next(){
Counter ++;
//ConList = new List<Contact>
ConList = [select Id, Name,FirstName, LastName from contact ORDER BY name
Limit 10 OFFSET 10
];
update ConList;
}
public void Previous(){
counter --;
conList = [select Id, Name,FirstName, LastName from Contact ORDER BY name limit 50 OFFSET 10];
update ConList;
}
}
and can you help me Account Names diplay its related contacts only in VF page
Please use Pagereference Method for Pagination and to display Account name use query like this,
Try this.....
<apex:form >
<apex:pageBlock title="Accounts" id="pgBlock">
<apex:pageBlockTable value="{!Accounts}" var="acc" id="pgTable">
<apex:column value="{!acc.Name}"/>
<apex:column value="{!acc.BillingCity}"/>
<apex:column value="{!acc.BillingState}"/>
<apex:column value="{!acc.Phone}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
status="status" disabled="{!DisablePrevious}" />
<apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
status="status" disabled="{!DisableNext}" />
<apex:actionStatus id="status" startText="Please Wait..."/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
==================
public with sharing class PagingController {
public PagingController (){
CountTotalRecords= [select count() from Account];
}
public Integer CountTotalRecords{get;set;}
public String QueryString {get;set;}
public Integer OffsetSize = 0;
private Integer QueryLimit = 5;
public list lstAccount;
public list getAccounts(){
lstAccount = new list();
lstAccount = [Select id, Name, BillingCity, BillingState, Phone from Account order by Name limit :QueryLimit offset :OffsetSize];
return lstAccount;
}
public Boolean getDisablePrevious(){
if(OffsetSize>0){
return false;
}
else return true;
}
public Boolean getDisableNext() {
if (OffsetSize + QueryLimit < countTotalRecords){
return false;
}
else return true;
}
public PageReference Next() {
OffsetSize += QueryLimit;
return null;
}
public PageReference Previous() {
OffsetSize -= QueryLimit;
return null;
}
}
public Integer CountTotalRecords{get;set;}
public String QueryString {get;set;}