2017-04-27 2 views
0

I quoi trier le tableau par le champ Numéro de commande: Check Listpourquoi case cochée plus élevée que sans contrôle dans le tableau de Visualforce

J'ai un WrapperClass qui implémente l'interface Comparable:

public class CheckListWrapper implements Comparable 
{ 
    public Boolean isChecked {get; set;} 
    public String shortDescription {get; set;} 
    public String fullDescription {get; set;} 
    public Integer order {get; set;} 
    public CheckList__c checkList; 
    public CheckListItem__c checkListItem; 

    public CheckListWrapper(CheckList__c chList) 
    { 
     shortDescription = chList.Short_Description__c; 
     fullDescription = chList.Full_Description__c; 
     order = (Integer)chList.Order__c; 
     isChecked = false; 
     checkList = chList; 
    } 

    public CheckListWrapper(CheckListItem__c chListItem) 
    { 
     shortDescription = chListItem.CheckList__r.Short_Description__c; 
     fullDescription = chListItem.CheckList__r.Full_Description__c; 
     order = (Integer)chListItem.CheckList__r.Order__c; 
     isChecked = true; 
     checkListItem = chListItem; 
    } 

    public Integer compareTo(Object compareTo) 
    { 
     CheckListWrapper compareToCheckList = (CheckListWrapper)compareTo; 
     Integer returnValue = 0; 
     if (checkList != null) 
     { 
      if (checkList.Order__c > compareToCheckList.checkList.Order__c) 
      { 
       returnValue = 1; 
      } else if (checkList.Order__c < compareToCheckList.checkList.Order__c) 
      { 
       returnValue = -1; 
      } 
     } else if (checkListItem != null) 
     { 
      if (checkListItem.CheckList__r.Order__c > compareToCheckList.checkListItem.CheckList__r.Order__c) 
      { 
       returnValue = 1; 
      } else if (checkListItem.CheckList__r.Order__c < compareToCheckList.checkListItem.CheckList__r.Order__c) 
      { 
       returnValue = -1; 
      } 
     } 

     return returnValue; 
    } 
} 

interface fonctionne comparables mais tout vérifié cases sont plus élevés que non vérifiés. La question est pourquoi les cases à cocher cochées sont plus élevées que non cochées et comment pourrait-on l'éviter?

Répondre

0

Bien. J'ai compris mon erreur: Tout va bien, mais je devais utiliser un bloc sinon dans la méthode compareTo et ne pas faire référence au champ Order__c à travers l'Object CheckList__c. Je devais utiliser la variable "order" de CheckListWrapper:

public Integer compareTo(Object compareTo) 
    { 
     CheckListWrapper compareToCheckList = (CheckListWrapper)compareTo; 
     Integer returnValue = 0; 
     if (order > compareToCheckList.order) 
     { 
      returnValue = 1; 
     } else if (order < compareToCheckList.order) 
     { 
      returnValue = -1; 
     } 

     return returnValue; 
    }