0

I have a VF page displaying a pageblocktable, and I need to be able to sort the columns (most importantly the "name" column. Can anybody assist. Here are the relevant snippets of code from my VF page and Controller.

VF PAGE:

  <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
                <apex:variable value="{!-1}" var="index" />
           <apex:column >
                    <apex:facet name="header">
                        <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                    </apex:facet>
                    <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
          </apex:column>
          <apex:column >
                    <apex:outputText >
                    <apex:variable value="{!index + 1}" var="index" />
                    {!index}
                    </apex:outputText>
            </apex:column>
            <apex:column headerValue="Name" value="{!accWrap.acc.contentdocumentid}" />
            <apex:column headerValue="Owner" value="{!accWrap.acc.owner.name}" />
            <apex:column headerValue="Last Modified" value="{!accWrap.acc.ContentModifiedDate}" /> 
            <apex:column headerValue="Size" value="{!accWrap.acc.ContentSize}" /> 
            </apex:pageBlockTable>

CONTROLLER:

public Id referralId { get; set; }
public Lead ref { get; set; }
public Id userId {get; set;}
public static boolean flag = true;
public string dateOfBirth {get; set;}
public string expensiveMeds {get; set;}
public List<ContentDocumentLink> listofattach {get; set;}
public List<wrapAccount> wrapAccountList {get; set;}
public List<contentversion> selectedAccounts{get;set;}
public List<ContentDocumentLink> attachmentsFullList {get; set;}
public boolean allSet {get;set;}
public boolean showFilesSection {get;set;}
public boolean authAlreadyRequested {get;set;}
 public FileDeletionPageController(ApexPages.StandardController controller) {
     ref = (Lead) controller.getRecord();
     referralId = ref.Id;
    userId = UserInfo.getUserId();
      Lead ref = [select id,Name,Patient_DOB__c,Insurance_Company_formula__c,PayerPolicy__c, facility__r.name, Primary_Diagnosis__c,Referral_Account_formula__c
                   from lead where id = :ref.id];
     
      dateOfBirth = string.valueof(ref.Patient_DOB__c);
      string year = dateOfBirth.substring(0,4);
      string month = dateOfBirth.substring(5,7);
      string day = dateOfBirth.substring(8,10);
      dateOfBirth = month + '/' + day + '/' + year;
     
      listofattach = [SELECT Id, contentdocument.title,contentdocumentid FROM ContentDocumentLink where LinkedEntityId in (select id from lead where id = : referralId)];
     set<id> contentdocumentids = new set<id>();
     for (contentdocumentlink loa : listofattach){
         contentdocumentids.add(loa.ContentDocumentId);
     }
     List <ContentVersion> contentVersions = new list<contentversion>();
     contentVersions  = [SELECT title,owner.name,ContentModifiedDate, ContentSize, Attach_to_auth_request__c, FileExtension,contentdocumentid FROM ContentVersion WHERE ContentDocumentId in :contentdocumentids and  islatest !=false];
     set<id> filteredContentDocumentIds = new set<id>();
     for (contentVersion cont : contentVersions){
         filteredContentDocumentIds.add(cont.contentdocumentid);
     }
     attachmentsFullList = [SELECT Id, contentdocument.title,contentdocumentid FROM ContentDocumentLink where LinkedEntityId in (select id from lead where id = : referralId) and ContentDocumentId in :filteredContentDocumentIds];
     if (attachmentsFullList.size() > 0){
         showFilesSection = true;
     }
     
     
    if(wrapAccountList == null) {
        wrapAccountList = new List<wrapAccount>();
        for(contentversion a: contentversions) {
            wrapAccountList.add(new wrapAccount(a));
        }
    }
}


public class wrapAccount {
    public contentversion acc {get; set;}
    public Boolean selected {get; set;}
    public wrapAccount(contentversion a) {
        acc = a;
        selected = false;
    }
}
4
  • 2
    A web search for "apex list sort wrapper" turns up several results, including this one – David Cheng Apr 8 at 19:52
  • It looks like the suggestion there is to use a Comparable interface. How would I incorporate that into my current code? Would i need to delete my current "wrapAccount" class and replace it with a comparable interface class? Or would it be in addition. This is my first encounter with this type of programming so more detailed assistance would be greatly helpful and appreciated. – Michael M Apr 8 at 20:56
  • 1
    The comparable interface would be used if you want the controller to do the sorting based on user input from the page; If you want to let the user sort on the client side, for VF, then you can use jQuery Datatable – cropredy Apr 9 at 0:30
  • @cropredy the client side option would be better for us. I'm looking at the link, and for step 1, it says "Step 1 is to create a zip file that has folders called “js”, “images” and “css” with those components copied from the “media” folder of the DataTables distribution. You should also include one of the license files. This is then uploaded as a static resource, in this example called “jQueryDataTablesZip”." Do you know where I can find the "media" folder that it refers to? I don't see it on the links provided there- if you don't mind – Michael M Apr 9 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.