You need to sign in to do that
Don't have an account?
Harjeet Singh
Pagination not working plz help
I have a vf page and controller.
My pagination is not working properly.I need to display 20 recors per page and then clicking on next will show next 20 and so on.similarly for previous also.I have put 4 command button for my pagination Next,Last,Previous,First. When I am clicking on next the same 20 records are appearing.It means only buttons are appearing on UI but there functionality is not working.
Below are the codes for my page and controller.
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock title="Select Subscription" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Proceed " action="{!processSelected}" />
<apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
</apex:pageBlockButtons>
<apex:pageblockSection title="Subscriptions" collapsible="false" columns="1" >
<apex:pageBlockTable value="{!wrapSubscriptionList}" var="subWrap">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" />
</apex:facet>
<!--<apex:inputCheckbox value="{!subWrap.selected}" id="inputId"/>-->
<apex:inputCheckbox value="{!subWrap.selected}" id="inputId" disabled="{!NOT(subWrap.sub.csord__Status__c=='Active')}" />
</apex:column>
<!--<apex:column value="{!subWrap.sub.Name}" />-->
<apex:column headerValue="Subscription Name" >
<!--<apex:commandLink value="{!subWrap.sub.Name}" action="/{!subWrap.sub.Id}"/>-->
<apex:outputLink value="/{!subWrap.sub.Id}" target="_blank"> {!subWrap.sub.Name} </apex:outputLink>
</apex:column>
<apex:column value="{!subWrap.sub.csord__Status__c}" />
<apex:column value="{!subWrap.sub.csord__Account__c}" />
</apex:pageBlockTable>
</apex:pageblockSection>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/>
<apex:outputLabel value=" (page {!pageNumber} of {!totalPages})"/>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) >= setCon.ResultSize}" value="{!setCon.ResultSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}"/>
<apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}"/>
<apex:pageBlock />
<apex:pageblockSection title="Selected Subscriptions" collapsible="false" columns="1" >
<apex:pageBlockTable value="{!selectedSubscriptions}" var="c" id="table2" title="Selected Subscriptions" width="100%">
<!--<apex:column value="{!c.Name}" headerValue="Subscription Name"/>-->
<apex:column headerValue="Subscription Name" >
<apex:commandLink value="{!c.Name}" action="/{!c.Id}" target="_blank"/>
</apex:column>
<apex:column value="{!c.csord__Status__c}" headerValue="Status"/>
<apex:column value="{!c.csord__Account__c}" headerValue="Account"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I am attaching screen snaps to refer that also
I have businees demo on Friday and need to be resolve this before that at any cost.
Many thanks in advance.
Hope this time also you people came up with solution for me...
My pagination is not working properly.I need to display 20 recors per page and then clicking on next will show next 20 and so on.similarly for previous also.I have put 4 command button for my pagination Next,Last,Previous,First. When I am clicking on next the same 20 records are appearing.It means only buttons are appearing on UI but there functionality is not working.
Below are the codes for my page and controller.
public class HarjeetWrapper{ private Set<Id> selectedContactIds; public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [select Id, Name,csord__Status__c, csord__Account__c from csord__Subscription__c where csord__Account__c=:accountid ])); } return setCon; } set; } public List<csord__Subscription__c > getWrapSubscriptionList() { setCon.setpagesize(20); setCon.setpageNumber(1); return (List<csord__Subscription__c >) setCon.getRecords(); } public Integer getPageNumber(){ return this.setCon.getPageNumber(); } Public Integer getTotalPages(){ Decimal totalSize = this.setCon.getResultSize(); Decimal pageSize = this.setCon.getPageSize(); Decimal pages = totalSize/pageSize; return (Integer)pages.round(System.RoundingMode.CEILING); } //Our collection of the class/wrapper objects wrapAccount public List<wrapSubscription> wrapSubscriptionList {get; set;} public List<csord__Subscription__c> selectedSubscriptions{get;set;} public Boolean isCancel{get;set;} public string accountid; public HarjeetWrapper(){ accountid=ApexPages.currentPage().getParameters().get('id'); if(wrapSubscriptionList == null) { wrapSubscriptionList= new List<wrapSubscription>(); for(csord__Subscription__c s: [select Id, Name,csord__Status__c, csord__Account__c from csord__Subscription__c where csord__Account__c=:accountid LIMIT 20]) { // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList wrapSubscriptionList.add(new wrapSubscription(s)); } } } public void processSelected() { selectedSubscriptions = new List<csord__Subscription__c>(); for(wrapSubscription wrapSubscriptionObj : wrapSubscriptionList) { if(wrapSubscriptionObj.selected == true) { selectedSubscriptions.add(wrapSubscriptionObj.sub); } } } public PageReference cancel(){ return new PageReference('/'+accountid); } public void next(){ if(this.setCon.getHasNext()) this.setCon.next(); } public void previous(){ if(this.setCon.getHasPrevious()) this.setCon.previous(); } // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value public class wrapSubscription { public csord__Subscription__c sub {get; set;} public Boolean selected {get; set;} public wrapSubscription(csord__Subscription__c s) { sub = s; selected = false; } } }<apex:page controller="HarjeetWrapper" sidebar="false" showHeader="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock title="Select Subscription" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Proceed " action="{!processSelected}" />
<apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
</apex:pageBlockButtons>
<apex:pageblockSection title="Subscriptions" collapsible="false" columns="1" >
<apex:pageBlockTable value="{!wrapSubscriptionList}" var="subWrap">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" />
</apex:facet>
<!--<apex:inputCheckbox value="{!subWrap.selected}" id="inputId"/>-->
<apex:inputCheckbox value="{!subWrap.selected}" id="inputId" disabled="{!NOT(subWrap.sub.csord__Status__c=='Active')}" />
</apex:column>
<!--<apex:column value="{!subWrap.sub.Name}" />-->
<apex:column headerValue="Subscription Name" >
<!--<apex:commandLink value="{!subWrap.sub.Name}" action="/{!subWrap.sub.Id}"/>-->
<apex:outputLink value="/{!subWrap.sub.Id}" target="_blank"> {!subWrap.sub.Name} </apex:outputLink>
</apex:column>
<apex:column value="{!subWrap.sub.csord__Status__c}" />
<apex:column value="{!subWrap.sub.csord__Account__c}" />
</apex:pageBlockTable>
</apex:pageblockSection>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/>
<apex:outputLabel value=" (page {!pageNumber} of {!totalPages})"/>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) >= setCon.ResultSize}" value="{!setCon.ResultSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}"/>
<apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}"/>
<apex:pageBlock />
<apex:pageblockSection title="Selected Subscriptions" collapsible="false" columns="1" >
<apex:pageBlockTable value="{!selectedSubscriptions}" var="c" id="table2" title="Selected Subscriptions" width="100%">
<!--<apex:column value="{!c.Name}" headerValue="Subscription Name"/>-->
<apex:column headerValue="Subscription Name" >
<apex:commandLink value="{!c.Name}" action="/{!c.Id}" target="_blank"/>
</apex:column>
<apex:column value="{!c.csord__Status__c}" headerValue="Status"/>
<apex:column value="{!c.csord__Account__c}" headerValue="Account"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I am attaching screen snaps to refer that also
I have businees demo on Friday and need to be resolve this before that at any cost.
Many thanks in advance.
Hope this time also you people came up with solution for me...
https://forcespider.wordpress.com/2013/02/06/dynamiccolumn/
the code which you are reffereing to i applied in my codes but still not able to get the result.So i pasted my codes here in order to get fine tune it.
Please look into my code and fine tune it wherever possible as i am not able to find out the blocker.
You can refer this code for pagination, this will work perfect, this is paginatore class which you can extend from your controller adn initalize the necessary variables and then you will be able to use it..
you can extend this calss from your main controller and then you can initalize the variables from your controller constructor
call this initalize method from constructor to inatlize
in total rows you can assign the list which contains the records...
you can additionally add this method in controller to go to any page directly
now in page you can simply iterate this wrapper class and add button as below adn this will work perfect
page code
above page code is mine old code..you can simply refer how i used list in repeat and show teh buttons for pagination..
please check above code and let me know if that work for you...
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
Apart from checkbox greyed out and pagination i need to perform proceed action with the help of a proceed button which will display all the selected rows and a cancel button which will redirect the user to home page from where the whole process started.these things are working absolutely fine in current scenario.
My above code is only for Pagination..it will not affect anything in your code..but you should implement it correctly...it is simple one .you can implement and use this..I will see if I will have time I will try to check your code adn will modify that if needed so you can use that code only..
but you can try this also and it will not affect anything..
just take backup and try..if you are unable to implement properly then you can revert everything as it is now..
Thanks,
Sandeep
For me in current scenario everything is working except that paginations button,but if i implement your code then i will end up with only pagination.
Thanks a ton for your non-stop help.I really appreciate your help.
Sure! You can keep everything as it..because except pagination everything is working for you..After you rdemo you can implement pagination or may be bfore that also you will be able to figure out the pagination issue
All the best for demo
Will check if i can find time and solve your current pagination logic..
Thanks,
Sandeep
Pls update my code according to my requiremnt if possible and you get time.