+ Start a Discussion
rvkrvk 

Pagination for a table using wrapper class

How to paginate a page block table which is using a wrapper class to display a list of rows.

SrinuSrinu
Hi rvk,
I just paste some code which i did before for pagination. By calling wrapper list from front end you can retrieve the records into front end.
//
//Class to 'output SFDC Content to a VisualForce page'
//
public class ContentVersionAlt{
   public List<ContentVersion> contentversionPagination;
   public List<FormatContentVersionWrapper> formatContentVersionPagination;
   
   public List<ContentVersion> contentversionPaginationFull;
   public Integer pageNumber {get; set;}
   public Boolean isNavigation = false; 
   
   public List<ContentVersion> results;
   public Boolean isSearch {get; set;}
  
   
   //Wrapper class which holds the List of content Version Records.
   public class FormatContentVersionWrapper {
       public ContentVersion formatContentVersion {get; set;}
       //COnstructor for wrapper class.
       public FormatContentVersionWrapper(ContentVersion cv) {
           this.formatContentVersion = cv;
           //this.contentSize = this.FileSizeToString(Long.valueOf(String.valueOf(contSize)));
           
       }
       
      
       
       
    
    //Contructor for class.   
    public ContentVersionAlt() {
        pageNumber = 0;
        //isSearch  = false;
       //type = ApexPages.currentPage().getParameters().get('type');        
    }
    
    //wrapper class Method, which calls actual class method for retreiving the contentversion records into wrapper list.
    public List<FormatContentVersionWrapper> getFormatContentVersionPagination() {        
        
        formatContentVersionPagination = new List<FormatContentVersionWrapper>();
        for(ContentVersion cv: contentversionPagination) {
            FormatContentVersionWrapper  fContVerWrapper = new FormatContentVersionWrapper(cv);
            formatContentVersionPagination.add(fContVerWrapper);
        }
        return formatContentVersionPagination;
        
    }
    
    //Method for retrieving Content, based on Type & Library.
    public List<ContentVersion> getcontentversionPagination(){
        
        Integer startIndex = pageNumber * 25;
        Integer endIndex = startIndex + 25;
        
       
        
        if(library != null && library != '') {
            if(contentversionPagination == null){
                contentversionPagination = new List<ContentVersion>();
                
                String query = 'Select Id, Title, LastModifiedDate, Content_Type__c, ContentDocumentId,Description,ContentSize From ContentVersion ';                
                 if(type != null && type != '') {
                    //String tempType = [Select Id, Content_Type__c from ContentVersion where Id =: type limit 1].Content_Type__c;
                       //query  += ' where Content_Type__c = \''+type+'\'';                      
                       query  += ' where Content_Type__c Includes (\''+type+'\') AND IsLatest = true';
                 }
                    if(isFirstCall && sortColumn  != null && sortColumn != '') {
                        query += ' Order By '+ sortColumn + '   ' +sortOrder;
                    }
                isFirstCall = false;
                 ContentWorkSpace contWorkSpace = [Select Id, Name from ContentWorkspace where id =: library];
                 List<ContentWorkspaceDoc> contWSDocList = [Select ContentDocumentId, ContentWorkspaceId from ContentWorkspaceDoc where ContentWorkspaceId =: contWorkSpace.Id];
                 Set<Id> validContIdSet = new Set<Id>();
                    for(ContentWorkspaceDoc contWSDoc : contWSDocList ) {
                        validContIdSet.add(contWSDoc.ContentDocumentId);
                    }
                 
                List<ContentVersion> contentversionPaginationBeforeFull  = (List<ContentVersion>)Database.query(query);
                contentversionPaginationFull = new List<ContentVersion>();
                    for(ContentVersion cv : contentversionPaginationBeforeFull) {
                        if(validContIdSet.contains(cv.ContentDocumentId)) {
                            contentversionPaginationFull.add(cv);
                        }
                    }
                
                for(Integer i=startIndex; i < endIndex && i < contentversionPaginationFull.size(); i++)                
                contentversionPagination.add(contentversionPaginationFull[i-0]);
                
            } else if(isNavigation) {
                contentversionPagination = new List<ContentVersion>();
                isNavigation = false;
                
                for(Integer i=startIndex; i < endIndex && i < contentversionPaginationFull.size(); i++)
                contentversionPagination.add(contentversionPaginationFull[i-0]);
            }        
        
        }         
        return contentversionPagination;
    
    }
    
    
    //
    //These methods are for pagination.
    //
    
    //returns the first page of records
    
    public void first() {
        isNavigation = true;
        pageNumber = 0;
    }
    
    //returns the last page of records
    public void last() {
        isNavigation = true;
        pageNumber = (contentversionPaginationFull.size()/25);
        if((pageNumber*25) == contentversionPaginationFull.size())
        pageNumber = pageNumber--;
    }
    
    //returns the previous page of records
    public void previous() {
        isNavigation = true;        
        if(pageNumber > 0)
            pageNumber--;
    }
    
    //returns the next page of records
    public void next() {
        isNavigation = true;        
        pageNumber++;
    }
    
    
}

 

sdharsdhar

Other way of doing it

 

http://richardvanhook.com/2009/08/03/visualforce-pagination-with-apex-lang/

 

Install apex-lang and use these methods.Simple and straight forward

rvkrvk

Hi Srinu,

 

Thanks for the reply. I have gone through your code , if you could post visual force page code that would give me a clear picture. thanks again.