Salesforce: Pagination in Visualforce Page
Pagination on the Visualforce page:
//Created First,Next,Last,Previous button along with number of record count
//Above buttons styling in the VF page
//Apex class code to get the data with pagination
//Created First,Next,Last,Previous button along with number of record count
<apex:outputPanel rendered="{!taskTotalRecordCount>0}" layout="block" styleClass="pageblockIconBlock">
<apex:commandButton styleClass="pageblockIconStyle" value="<<" status="pageLoading" rerender="resultTable" action="{!FirstPageCompletedTaskData}" disabled="{!preveviousdata}"/>
<apex:commandButton styleClass="pageblockIconStyle" value="<" status="pageLoading" rerender="resultTable" action="{!PreviousPageCompletedTaskData}" disabled="{!preveviousdata}"/>
<apex:outputText style="padding-left:15px;padding:5px;" > {!(taskCompletedRecordOffsetSize+1)}-{!IF((taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize)>taskTotalRecordCount, taskTotalRecordCount,(taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize))} of <font class="orangeText">{!taskTotalRecordCount}</font></apex:outputText>
<apex:commandButton styleClass="pageblockIconStyle" value=">" status="pageLoading" rerender="resultTable" action="{!NextPageCompletedTaskData}" disabled="{!nextdata}"/>
<apex:commandButton styleClass="pageblockIconStyle" value=">>" status="pageLoading" rerender="resultTable" action="{!LastPageCompletedTaskData}" disabled="{!nextdata}"/>
</apex:outputPanel>
<apex:commandButton styleClass="pageblockIconStyle" value="<<" status="pageLoading" rerender="resultTable" action="{!FirstPageCompletedTaskData}" disabled="{!preveviousdata}"/>
<apex:commandButton styleClass="pageblockIconStyle" value="<" status="pageLoading" rerender="resultTable" action="{!PreviousPageCompletedTaskData}" disabled="{!preveviousdata}"/>
<apex:outputText style="padding-left:15px;padding:5px;" > {!(taskCompletedRecordOffsetSize+1)}-{!IF((taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize)>taskTotalRecordCount, taskTotalRecordCount,(taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize))} of <font class="orangeText">{!taskTotalRecordCount}</font></apex:outputText>
<apex:commandButton styleClass="pageblockIconStyle" value=">" status="pageLoading" rerender="resultTable" action="{!NextPageCompletedTaskData}" disabled="{!nextdata}"/>
<apex:commandButton styleClass="pageblockIconStyle" value=">>" status="pageLoading" rerender="resultTable" action="{!LastPageCompletedTaskData}" disabled="{!nextdata}"/>
</apex:outputPanel>
//Above buttons styling in the VF page
.pageblockIconBlock {
background: #F1F0F0;
height: 32px;
padding-top: 3px;
padding-left: 5px;
}
body .pageblockIconBlock input.btnDisabled, body .pageblockIconBlock .input.btnCancel {
background: #AAAAAA !important;
}
.pageblockIconStyle {
background: #F79328 !important;
color: white !important;
border: 0px !important;
border-radius: 0px !important;
width: 25px;
height: 25px;
}
background: #F1F0F0;
height: 32px;
padding-top: 3px;
padding-left: 5px;
}
body .pageblockIconBlock input.btnDisabled, body .pageblockIconBlock .input.btnCancel {
background: #AAAAAA !important;
}
.pageblockIconStyle {
background: #F79328 !important;
color: white !important;
border: 0px !important;
border-radius: 0px !important;
width: 25px;
height: 25px;
}
//First time this method will be executed to get the total number of record count and reset the values
public List<Account> accountList { get; set; }
public void pullthe AccountDetails() {
resetTheOffSetValues();
accountList = new List<Account>();
taskTotalRecordCount = Database.countQuery('SELECT count() FROM Account');
pullMatchingAccountDetails();
}
public void pullMatchingAccountDetails() {
accountList = (List<Account>) Database.query('SELECT Id,Name FROM ACCOUNT ORDER By Name LIMIT :taskCompletedRecordLimitSize OFFSET :taskCompletedRecordOffsetSize');
}
//Initialize the values
private void resetTheOffSetValues() {
taskTotalRecordCount = 0;
taskCompletedRecordOffsetSize = 0;
taskCompletedRecordLimitSize = 10; //Set the limit here to display the number of record in VF page
}
//Initialize the record offset size
public void FirstPageCompletedTaskData() {
taskCompletedRecordOffsetSize = 0;
pullMatchingAccountDetails();
}
//Initialize the privously viewed matching accounts record offset size
public void PreviousPageCompletedTaskData() {
taskCompletedRecordOffsetSize =taskCompletedRecordOffsetSize - taskCompletedRecordLimitSize;
pullMatchingAccountDetails();
}
//Initialize the next viewed matching accounts record offset size
public void NextPageCompletedTaskData() {
taskCompletedRecordOffsetSize = taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize;
pullMatchingAccountDetails();
}
//Initialize the Last page matching accounts record offset size
public void LastPageCompletedTaskData() {
taskCompletedRecordOffsetSize =taskTotalRecordCount - math.mod(taskTotalRecordCount,taskCompletedRecordLimitSize);
pullMatchingAccountDetails();
}
//Disable the Previous button on account matching list based on the record offset size.
public boolean getpreveviousdata() {
if(taskCompletedRecordOffsetSize == 0)
return true;
else
return false;
}
//Disable the Next button on account matching list based on the conditions.
public boolean getnextdata() {
if((taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize) > taskTotalRecordCount)
return true;
else
return false;
}
public List<Account> accountList { get; set; }
public void pullthe AccountDetails() {
resetTheOffSetValues();
accountList = new List<Account>();
taskTotalRecordCount = Database.countQuery('SELECT count() FROM Account');
pullMatchingAccountDetails();
}
public void pullMatchingAccountDetails() {
accountList = (List<Account>) Database.query('SELECT Id,Name FROM ACCOUNT ORDER By Name LIMIT :taskCompletedRecordLimitSize OFFSET :taskCompletedRecordOffsetSize');
}
//Initialize the values
private void resetTheOffSetValues() {
taskTotalRecordCount = 0;
taskCompletedRecordOffsetSize = 0;
taskCompletedRecordLimitSize = 10; //Set the limit here to display the number of record in VF page
}
//Initialize the record offset size
public void FirstPageCompletedTaskData() {
taskCompletedRecordOffsetSize = 0;
pullMatchingAccountDetails();
}
//Initialize the privously viewed matching accounts record offset size
public void PreviousPageCompletedTaskData() {
taskCompletedRecordOffsetSize =taskCompletedRecordOffsetSize - taskCompletedRecordLimitSize;
pullMatchingAccountDetails();
}
//Initialize the next viewed matching accounts record offset size
public void NextPageCompletedTaskData() {
taskCompletedRecordOffsetSize = taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize;
pullMatchingAccountDetails();
}
//Initialize the Last page matching accounts record offset size
public void LastPageCompletedTaskData() {
taskCompletedRecordOffsetSize =taskTotalRecordCount - math.mod(taskTotalRecordCount,taskCompletedRecordLimitSize);
pullMatchingAccountDetails();
}
//Disable the Previous button on account matching list based on the record offset size.
public boolean getpreveviousdata() {
if(taskCompletedRecordOffsetSize == 0)
return true;
else
return false;
}
//Disable the Next button on account matching list based on the conditions.
public boolean getnextdata() {
if((taskCompletedRecordOffsetSize + taskCompletedRecordLimitSize) > taskTotalRecordCount)
return true;
else
return false;
}
Comments
Post a Comment