+ 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 ;
    //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);
            return 0;
    //navigates to next page
    public void nextPage()
        if(TotalRows== 0 || PageSize == 0) return;
        if(FirstPage + PageSize < TotalRows)
            FirstPage += PageSize ;
    //navigates to first page
    public void firstPage()
        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%">
                                 <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>
                                         <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 action="{!previousPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,key4,pbt1">
                                                 <img src="/s.gif" class="prev" />Previous
                                         <apex:outputText rendered="{!(page == lastPage)}">
                                                 <font color="#A8A8A8">Next</font>
                                                <img src="/s.gif" class="nextoff"/>
                                             <img src="/s.gif" class="lastoff" />
                                         <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 action="{!lastPage}" style="text-decoration:none;" rerender="block,pbskey1,pbtkey1,pbt1">
                                                 <img src="/s.gif" class="last" />
                                     <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" />
                        <div style="clear:both"></div>