function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kushal MishraKushal Mishra 

Pagination in wrapper class with objects

Please help its urgent!!

i have a wrapper class. there are two object notes and attachment i have got combine data on one vf page perfectly but i am not able to set pagination on this....plese help.please have a look of part of code please tell me how can we set offset or any other method?

public List<wrapper> getnoteAndAtt() {
  lstnote  = new List<Note>();
  lstw = new List<wrapper>();
  lstatt = new List<Attachment>();

lstatt = [SELECT CreatedDate,LastModifiedDate,Name FROM Attachment where ParentId=: recId];

lstnote = [SELECT CreatedDate,LastModifiedDate,Title FROM Note where ParentId=: recId];

for(Integer i=0;i<lstatt.size();i++){
//lstw.add(new wrapper(lstnote[i].title,lstatt[i].name,lstatt[i].CreatedDate,lstatt[i].LastModifiedDate));
lstw.add(new wrapper(lstatt[i].name,true,false,lstatt[i].CreatedDate, lstatt[i].LastModifiedDate, 'Attachment'));
//lstw.add(new wrapper(lstatt[i].CreatedDate,true,false));
}


for(Integer i=0;i<lstnote.size();i++){
//lstw.add(new wrapper(lstnote[i].title,lstatt[i].name,lstatt[i].CreatedDate,lstatt[i].LastModifiedDate));
lstw.add(new wrapper(lstnote[i].title,false,true,lstnote[i].CreatedDate,lstnote[i].LastModifiedDate, 'Note'));
//lstw.add(new wrapper(lstnote[i].title,true,false));

}

return lstw;
sandeep sankhlasandeep sankhla
Hi Kushal,

You can simply use custom pagination here and bind your wrapper class list to add the pagination functionality

this is pagination class which you should implement from your controller
public abstract class  paginator1 {
    public Integer FirstPage {get; set;} // first row number in the list.
    public Integer PageSize {get; set;} // number of rows per page. //previously currentPageCount
    public Integer LastPage {get; set;} // row index of the first record the in the last page
    public Integer TotalRows; // total rows in all pages.
    public Integer page{get; set;}
    
    //navigates to previous page
    public void previousPage()
    {
        
        if(FirstPage - PageSize >= 0)
        {
            FirstPage -= PageSize ;
           page--;
        }
       
    }
    
    //navigates to last page
    public void lastPage()
    {    
        FirstPage = calcLastPage();
        
    }
    
    //calculates page number of last page
    private Integer calcLastPage()
    {
        if(TotalRows >= PageSize )
        {
            page=Math.mod(TotalRows, PageSize) == 0 ? TotalRows/PageSize : TotalRows/PageSize + 1;
            return ((page-1)*5);
        }
        else
        {
            return 0;
        }
    }
    
    //navigates to next page
    public void nextPage()
    {
        
        if(TotalRows== 0 || PageSize == 0) return;
        
        if(FirstPage + PageSize < TotalRows)
        {
            FirstPage += PageSize ;
            page++;
        }
    }
    
    //navigates to first page
    public void firstPage()
    {
        page=1;
        FirstPage = 0;
    }   
    
   

}
===============================

This is page code to add this on page and bind your wrapper class, please modify and add your wrapper class

<div style="position:relative; width:100% height:30px; text-align:center;" class="paginator">
                        <table width="100%">
                            <tr>
                                 <td style="text-align: right;padding-left: 400px; ">
                                         <apex:outputText rendered="{!(page== 1||page==0)}">
                                              <img src="/s.gif" class="firstoff"/>&nbsp;
                                              <span class="prevNext">
                                                   <img src="/s.gif" class="prevoff" />  
                                                  <font color="#A8A8A8">Previous</font>
                                              </span>&nbsp;
                                         </apex:outputText>
                                         <apex:outputText rendered="{!!(page==1||page==0)}">
                                             <apex:commandLink action="{!firstPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,key4,pbt1">
                                                 <img src="/s.gif" class="first"/>
                                             </apex:commandLink>&nbsp;
                                             <apex:commandLink action="{!previousPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,key4,pbt1">
                                                 <img src="/s.gif" class="prev" />Previous
                                             </apex:commandLink>&nbsp;
                                         </apex:outputText>
                                         <apex:outputText rendered="{!(page == lastPage)}">
                                             <span>
                                                 <font color="#A8A8A8">Next</font>
                                                <img src="/s.gif" class="nextoff"/>
                                             </span>&nbsp;
                                             <img src="/s.gif" class="lastoff" />
                                             
                                         </apex:outputText>
                                         <apex:outputtext rendered="{!!(page == lastPage)}">
                                             <apex:commandLink action="{!nextPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,key4,pbt1">Next
                                                 <img src="/s.gif" class="next"/>
                                             </apex:commandLink>&nbsp;
                                             <apex:commandLink action="{!lastPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,pbt1">
                                                 <img src="/s.gif" class="last" />
                                             </apex:commandLink>
                                         </apex:outputtext>
                                     </td>
                                     <td style="text-align:right; padding-left: 450px;">
                                         &nbsp;&nbsp;&nbsp;Page:<apex:inputText value="{!page}" onKeyPress="return onlyNum(event);" id="key4" size="1">
                                         </apex:inputText> &nbsp;&nbsp;&nbsp;of &nbsp;&nbsp;{!LastPage}
                                         <apex:actionFunction name="gotopage" action="{!gotopage}" rerender="pbskey1,key4,pbskey5" />
                                         
                                     </td>
                                 </tr>
                            </table>
                        </div>
                        <div style="clear:both"></div>