You need to sign in to do that
Don't have an account?
learning1.3953795511514497E12
Pageblocktable pagination is not working properly
Hi,
I have created a pageblocktable with pagination by refering to " http://www.redpointsolutions.com/add-pagination-to-your-visualforce-pages-using-the-soql-offset-clause ". My code is as below...
VF PAGE
==============
<apex:page title="Salesforce SOQL Offset Example Using Visualforce" controller="soql_offset_example" showHeader="false" sidebar="false" readOnly="true" cache="false">
<apex:sectionHeader subtitle="SOQL Offset Example" title="Square Root Table"/>
<apex:pageBlock >
<apex:pageBlockButtons location="top" >
<apex:outputPanel id="myButtons">
<apex:form >
<apex:commandButton action="{!Beginning}" title="Beginning" value="<<" disabled="{!disablePrevious}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!Previous}" title="Previous" value="<" disabled="{!disablePrevious}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!Next}" title="Next" value=">" disabled="{!disableNext}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!End}" title="End" value=">>" disabled="{!disableNext}" reRender="myPanel,myButtons"/>
</apex:form>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Numbers and their Square Roots (Total List Size: {!total_size})" collapsible="false">
<apex:outputPanel id="myPanel">
<apex:pageMessages id="theMessages" />
<apex:pageBlockTable value="{!LinkedinCompanies}" var="l" align="center">
<apex:column value="{!l.id}" />
<apex:column value="{!l.name}" />
<apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Controller
============
public with sharing class soql_offset_example {
private integer counter=0; //keeps track of the offset
private integer list_size=5; //sets the page size or number of rows
public integer total_size; //used to show user the total size of the list
String linkedinResponse;
public List<companyDetails> LinkedinCompanies{get;set;}
public class companyDetails
{
public Integer id {get;set;}
public String name {get;set;}
public String universalName {get;set;}
Public String size {get;set;}
Public String industry {get;set;}
Public String ticker {get;Set;}
public String logoURL{get;set;}
public string websiteurl {get;set;}
public String description {get;set;}
Public locationDetails locations{get;set;}
}
public class locationDetails
{
public integer lin_total{get;set;}
public List<locationValues> values{get;set;}
}
public class locationValues
{
public addressDetails address{get;set;}
public contactDetails contactInfo{get;set;}
}
public class addressDetails
{
public String city{get;set;}
public String postalCode{get;set;}
public String street1{get;set;}
}
public class contactDetails
{
public String fax{get;set;}
public String phone1{get;set;}
}
public soql_offset_example()
{
//total_size = 20; //set the total size in the constructor
getNumbers();
}
public void getNumbers() {
try
{
linkedinResponse = '{"companies": { "_count": 10, "_start": 0, "_total": 55573, "values": [ { "id": 10667, "industry": "Internet", "name": "Facebook" }, { "id": 3748947, "industry": "Marketing & Advertising", "name": "Community Management Facebook y Facebook Ads" }, { "id": 3219314, "industry": "Marketing & Advertising", "name": "Smart Facebook Likes" }, { "id": 2620756, "industry": "Information Technology & Services", "name": "Revolucionamos Facebook" }, { "id": 3326206, "industry": "Marketing & Advertising", "name": "Facebook-buy-fans.com" }, { "id": 2811427, "industry": "Marketing & Advertising", "name": "Empowers Facebook Marketing for Business" }, { "id": 2226401, "industry": "Marketing & Advertising", "name": "Facebook Advertising" }, { "id": 5059292, "industry": "Internet", "name": "Facebook Covers" }, { "id": 3100592, "industry": "Real Estate", "name": "Facebook Property Listing by propertybooster.com" }, { "id": 2453105, "industry": "Accounting", "name": "FaceBook Business Page Your Biz First" } ] }}';
linkedinResponse =linkedinResponse.replace('"_', '"lin_');
System.debug('********** linkedinResponse *******' +linkedinResponse);
Map<String, Object> linkedinRespCompanies = (Map<String, Object>) JSON.deserializeUntyped(linkedinResponse);
Map<String,Object> CompaniesMap = (Map<String,Object>)linkedinRespCompanies.get('companies');
List<Object> CompaniesList = (List<Object>)CompaniesMap.get('values');
String CompaniesListSerialized = JSON.serialize(CompaniesList);
LinkedinCompanies = (List<companyDetails>) JSON.deserializeStrict(CompaniesListSerialized, List<companyDetails>.class);
total_size = LinkedinCompanies.size();
}
catch (Exception e)
{
ApexPages.addMessages(e);
// return null;
}
}
public PageReference Beginning() { //user clicked beginning
counter = 0;
return null;
}
public PageReference Previous() { //user clicked previous button
counter -= list_size;
return null;
}
public PageReference Next() { //user clicked next button
counter += list_size;
return null;
}
public PageReference End() { //user clicked end
counter = total_size - math.mod(total_size, list_size);
return null;
}
public Boolean getDisablePrevious() {
//this will disable the previous and beginning buttons
if (counter>0) return false; else return true;
}
public Boolean getDisableNext() { //this will disable the next and end buttons
if (counter + list_size < total_size) return false; else return true;
}
public Integer getTotal_size() {
return total_size;
}
public Integer getPageNumber() {
return counter/list_size + 1;
}
public Integer getTotalPages() {
if (math.mod(total_size, list_size) > 0) {
return total_size/list_size + 1;
} else {
return (total_size/list_size);
}
}
}
Eventhough the button and footer are changing correctly, but the actual data is not changing in table according the list_size mentioned. Please help...
Anu
I have created a pageblocktable with pagination by refering to " http://www.redpointsolutions.com/add-pagination-to-your-visualforce-pages-using-the-soql-offset-clause ". My code is as below...
VF PAGE
==============
<apex:page title="Salesforce SOQL Offset Example Using Visualforce" controller="soql_offset_example" showHeader="false" sidebar="false" readOnly="true" cache="false">
<apex:sectionHeader subtitle="SOQL Offset Example" title="Square Root Table"/>
<apex:pageBlock >
<apex:pageBlockButtons location="top" >
<apex:outputPanel id="myButtons">
<apex:form >
<apex:commandButton action="{!Beginning}" title="Beginning" value="<<" disabled="{!disablePrevious}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!Previous}" title="Previous" value="<" disabled="{!disablePrevious}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!Next}" title="Next" value=">" disabled="{!disableNext}" reRender="myPanel,myButtons"/>
<apex:commandButton action="{!End}" title="End" value=">>" disabled="{!disableNext}" reRender="myPanel,myButtons"/>
</apex:form>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Numbers and their Square Roots (Total List Size: {!total_size})" collapsible="false">
<apex:outputPanel id="myPanel">
<apex:pageMessages id="theMessages" />
<apex:pageBlockTable value="{!LinkedinCompanies}" var="l" align="center">
<apex:column value="{!l.id}" />
<apex:column value="{!l.name}" />
<apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Controller
============
public with sharing class soql_offset_example {
private integer counter=0; //keeps track of the offset
private integer list_size=5; //sets the page size or number of rows
public integer total_size; //used to show user the total size of the list
String linkedinResponse;
public List<companyDetails> LinkedinCompanies{get;set;}
public class companyDetails
{
public Integer id {get;set;}
public String name {get;set;}
public String universalName {get;set;}
Public String size {get;set;}
Public String industry {get;set;}
Public String ticker {get;Set;}
public String logoURL{get;set;}
public string websiteurl {get;set;}
public String description {get;set;}
Public locationDetails locations{get;set;}
}
public class locationDetails
{
public integer lin_total{get;set;}
public List<locationValues> values{get;set;}
}
public class locationValues
{
public addressDetails address{get;set;}
public contactDetails contactInfo{get;set;}
}
public class addressDetails
{
public String city{get;set;}
public String postalCode{get;set;}
public String street1{get;set;}
}
public class contactDetails
{
public String fax{get;set;}
public String phone1{get;set;}
}
public soql_offset_example()
{
//total_size = 20; //set the total size in the constructor
getNumbers();
}
public void getNumbers() {
try
{
linkedinResponse = '{"companies": { "_count": 10, "_start": 0, "_total": 55573, "values": [ { "id": 10667, "industry": "Internet", "name": "Facebook" }, { "id": 3748947, "industry": "Marketing & Advertising", "name": "Community Management Facebook y Facebook Ads" }, { "id": 3219314, "industry": "Marketing & Advertising", "name": "Smart Facebook Likes" }, { "id": 2620756, "industry": "Information Technology & Services", "name": "Revolucionamos Facebook" }, { "id": 3326206, "industry": "Marketing & Advertising", "name": "Facebook-buy-fans.com" }, { "id": 2811427, "industry": "Marketing & Advertising", "name": "Empowers Facebook Marketing for Business" }, { "id": 2226401, "industry": "Marketing & Advertising", "name": "Facebook Advertising" }, { "id": 5059292, "industry": "Internet", "name": "Facebook Covers" }, { "id": 3100592, "industry": "Real Estate", "name": "Facebook Property Listing by propertybooster.com" }, { "id": 2453105, "industry": "Accounting", "name": "FaceBook Business Page Your Biz First" } ] }}';
linkedinResponse =linkedinResponse.replace('"_', '"lin_');
System.debug('********** linkedinResponse *******' +linkedinResponse);
Map<String, Object> linkedinRespCompanies = (Map<String, Object>) JSON.deserializeUntyped(linkedinResponse);
Map<String,Object> CompaniesMap = (Map<String,Object>)linkedinRespCompanies.get('companies');
List<Object> CompaniesList = (List<Object>)CompaniesMap.get('values');
String CompaniesListSerialized = JSON.serialize(CompaniesList);
LinkedinCompanies = (List<companyDetails>) JSON.deserializeStrict(CompaniesListSerialized, List<companyDetails>.class);
total_size = LinkedinCompanies.size();
}
catch (Exception e)
{
ApexPages.addMessages(e);
// return null;
}
}
public PageReference Beginning() { //user clicked beginning
counter = 0;
return null;
}
public PageReference Previous() { //user clicked previous button
counter -= list_size;
return null;
}
public PageReference Next() { //user clicked next button
counter += list_size;
return null;
}
public PageReference End() { //user clicked end
counter = total_size - math.mod(total_size, list_size);
return null;
}
public Boolean getDisablePrevious() {
//this will disable the previous and beginning buttons
if (counter>0) return false; else return true;
}
public Boolean getDisableNext() { //this will disable the next and end buttons
if (counter + list_size < total_size) return false; else return true;
}
public Integer getTotal_size() {
return total_size;
}
public Integer getPageNumber() {
return counter/list_size + 1;
}
public Integer getTotalPages() {
if (math.mod(total_size, list_size) > 0) {
return total_size/list_size + 1;
} else {
return (total_size/list_size);
}
}
}
Eventhough the button and footer are changing correctly, but the actual data is not changing in table according the list_size mentioned. Please help...
Anu
Ramesh Kalloori
Please use the below code.