+ Start a Discussion
springerwaspringerwa 

Pagination Not Working in Custom Controller for Sorting DataTable

I think I have read every hit I have found on how to call "Next" and "Previous" for pagination and have spend the better part of 12 hours on this and I am hoping that its easy and I am just missing the obvious...I tried each example I have come across on the board and I cannot get the "Next" button to display the remaining records I am calling.

 

I have this same page as the examples below using the StandardController for Opportunity and the "Next" and "Previous" works just fine but the records don't sort so it is a bit messy as there are generally 70 - 90 records that fit the "where" criteria at any giving time.  I wrote the CustomController from the posts on the boards and it sorts beautifully but I can only see 20 records - so while it is no longer messy, it is useless :-(

 

If someone can offer some advice on how to have a sorted list that also paginates - I would certainly appreciate it! (all this because no one wants to READ the stages of "Green", "Yellow" and "Red" they want the row to be painted the actual colors. GEEZ!)

 

 

public with sharing class SortOps { public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select name, territory.name, stagename, stagenumber__c, closedate,Account.BillingCity, Account.BillingState, Account.National_Account__c, Account.National_Account_Affiliation__c,Account_Type_Profile__c,Amount,Net_Unit_Price__c,Win_Timeframe__c,Competitive_Market__c,ID_d_Financial_Buyer__c,Approval_Process_Outlined__c,APV__c,Business_Plan_Presented__c,ID_d_Referral_Network__c,Documented_Referral_Network__c,ID_d_Budget_Year__c,Executive_Level_Meeting__c,ID_d_Clinical_Champion__c,System_Quotation_Presented__c,Project_Funded__c,Customer_Targeted_Purchase__c,ID_d_Referring_Physicians__c,BoD_Approval_Received__c,CreatedDate, recordtype.name from Opportunity where stagename = 'Yellow' OR stagename = 'Green' OR stagename='Red' Order BY recordtype.name, territory.name, stagenumber__c, closedate ASC])); } return setCon; } set; } public List<Opportunity> getOpportunities() { return (List<Opportunity>) setCon.getRecords(); } public PageReference next() { return null; } public PageReference previous() { return null; } public Boolean hasPrevious { get { return setCon.getHasPrevious(); } } public Boolean hasNext { get { return setCon.getHasNext(); } } }

 

 

<apex:page Controller="SortOps" recordSetVar="{!opportunities}"> <apex:form > <style> .dateFormat{display:none;} </style> <style type="text/css"> .h1 {background-color:#D8D8D8; border-width: 2px; border-spacing: 4px; padding: 2px; border-style: inset; border-color: :#D8D8D8; border-collapse: separate;} </style> <apex:pageBlock > <apex:pagemessages /> <apex:dataTable width="100%" border="1" id="DataTable" value="{!Opportunities}" var="o" id="opp_table" style="font-size:11px;text-align: center; vertical-align:top;word-wrap: break-word;height: 20px;" headerClass="h1" columnsWidth="150,70,130,70,20,40,80,120,30,30,120,50,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,120"> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height:20px;"> <apex:facet name="header"><b>Stage</b></apex:facet> <apex:OutputText value="{!o.stagename}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px; white-space: nowrap"> <apex:facet name="header"><b>Territory</b></apex:facet> <apex:OutputText value="{!o.territory.name}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80;',if(o.stagename='Yellow','background-color:#F3F781;','color:black')))}; height: 20px; text-align: left;white-space: nowrap"> <apex:facet name="header"><b>Opportunity Name</b></apex:facet> <a href="/{!o.Id}">{!o.Name }</a> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px; white-space: nowrap"> <apex:facet name="header"><b>Billing City</b></apex:facet> <apex:outputtext value="{!o.Account.BillingCity}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Billing State</b></apex:facet> <apex:outputtext value="{!o.Account.BillingState}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>National Account</b></apex:facet> <apex:outputField value="{!o.Account.National_Account__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px;white-space: nowrap"> <apex:facet name="header"><b>National Account Affiliation</b></apex:facet> <apex:Outputfield value="{!o.Account.National_Account_Affiliation__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px;white-space: nowrap"> <apex:facet name="header"><b>Market Segment - Account</b></apex:facet> <apex:outputField value="{!o.Account_Type_Profile__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};text-align: right; height: 20px; white-space: nowrap"> <apex:facet name="header"><b>Amount</b></apex:facet> <apex:outputfield value="{!o.Amount}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};text-align: right; height: 20px; white-space: nowrap"> <apex:facet name="header"><b>Net Unit Price</b></apex:facet> <apex:outputfield value="{!o.Net_Unit_Price__c}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Win Date</b></apex:facet> <apex:outputfield value="{!o.closeDate}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px;width: 50px"> <apex:facet name="header"><b>Fiscal Period</b></apex:facet> <apex:outputField value="{!o.Win_Timeframe__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px;"> <apex:facet name="header"><b>Competitive Market?</b></apex:facet> <apex:outputField value="{!o.Competitive_Market__c}" /> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>IDd Financial Buyer?</b></apex:facet> <apex:outputField value="{!o.ID_d_Financial_Buyer__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Approval Process Outlined?</b></apex:facet> <apex:outputField value="{!o.Approval_Process_Outlined__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Customer Targeted Purchase?</b></apex:facet> <apex:outputField value="{!o.Customer_Targeted_Purchase__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>System Quotation Presented?</b></apex:facet> <apex:outputField value="{!o.System_Quotation_Presented__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};font-weight:bold; height: 20px;"> <apex:facet name="header"><b>Current Annual Patient Volume</b></apex:facet> <apex:outputfield value="{!o.APV__c}" style="width: 40px" styleClass="title"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Business Plan Presented?</b></apex:facet> <apex:outputField value="{!o.Business_Plan_Presented__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>IDd Referral Network?</b></apex:facet> <apex:outputField value="{!o.ID_d_Referral_Network__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Documented Referral Network?</b></apex:facet> <apex:outputField value="{!o.Documented_Referral_Network__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>IDd Budget Year?</b></apex:facet> <apex:outputField value="{!o.ID_d_Budget_Year__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Executive Level Meeting?</b></apex:facet> <apex:outputField value="{!o.Executive_Level_Meeting__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>IDd Clinical Champion?</b></apex:facet> <apex:outputField value="{!o.ID_d_Clinical_Champion__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>System Quotation Presented?</b></apex:facet> <apex:outputField value="{!o.System_Quotation_Presented__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>Project Funded?</b></apex:facet> <apex:outputField value="{!o.Project_Funded__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>IDd Referring Physicians?</b></apex:facet> <apex:outputField value="{!o.ID_d_Referring_Physicians__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))};height: 20px;"> <apex:facet name="header"><b>BoD Approval Received?</b></apex:facet> <apex:outputField value="{!o.BoD_Approval_Received__c}"/> </div> </apex:column> <apex:column > <div style="{!if(o.StageName='Red','background-color:#FE2E2E', if(o.StageName='Green','background-color:#00FF80',if(o.stagename='Yellow','background-color:#F3F781','color:black')))}; height: 20px;white-space: nowrap"> <apex:facet name="header"><b>Created Date</b></apex:facet> <apex:outputField value="{!o.CreatedDate}"/> </div> </apex:column> ....... </apex:dataTable> <apex:panelGrid columns="2" style="font-weight: bold;"> <apex:commandLink action="{!previous}"><font color="blue">Previous</font></apex:commandLink> <apex:commandLink action="{!next}" ><font color="blue">Next</font></apex:commandLink> </apex:panelGrid> </apex:pageBlock> </apex:form> </apex:page>

 

WDF1234WDF1234

You might want to try this slight modification in your controller, it worked fine for me:

 

 

public PageReference next() { Integer p = setCon.getPageNumber(); if(hasNext) { setCon.setPageNumber(p+1); } return null; } public PageReference previous() { Integer p = setCon.getPageNumber(); if(hasPrevious) { setCon.setPageNumber(p-1); } return null; }

 

 

 

ranirani
Hi, I have achieved the pagination but how do we activate and deactivate the hyperlinks. For example i need to show only the next hyperlink on my VF page and accordingly show the next & previous links in the next page and then deactivate the next link when the next result do not fetch me any records. Is there any way to acheive this?