+ Start a Discussion
SjaleelSjaleel 

How to get total of each item to be displayed in the VF page

Dear Developers,

 

IAm creating a VF page for custome objects as detailed spec sheet,The object has a table list of with several items in it. Each item has got serail no, product no , desceription and so on. Some of the items are listed more than once and they just differ in serial number but the other are all the same. When displaying in the actual VF page I dont need the item to be repetead but total count of each item with.

 

22MCDUTHALES AVIONICS SAC19266DA01
22MCDUTHALES AVIONICS SAC19266DA01
22RUDDER TRIM CONTROL SWITCHGOODRICH ACTUATION SYSTEM SAS27-457
22RUDDER TRIM INDICATORECE EQUIPEMENT and CONSTRUCTION ELEC S196PN01Y02
23VHF/COMM.TRANSCEIVERHONEYWELL INTL INC DBA AEROSPACE ELE064-50000-0505
23VHF/COMM.TRANSCEIVERHONEYWELL INTL INC DBA AEROSPACE ELE064-50000-0505
23VHF/COMM.TRANSCEIVERHONEYWELL INTL INC DBA AEROSPACE ELE064-50000-0505
23RADIO MANAGEMENT PANELTHALES AVIONICS SAC12848CA01



This is the table being displayed, but as you see some items are repetitive, as that how it is in the actual objects page, so rather i'd like to have a total count or quantity of each item, how can that be done?

 

This is part of the code

 

 public List<Equipment__c> getEquipment(Aircraft__c aircraft)
    {
        List<Equipment__c> Equipment = new List<Equipment__c>();
       if (aircraft!=null)
        {
            Id aircraftID = aircraft.ID;
            Equipment = [select id, ATA__c, Description__c, Part_Number__c, Serial_Number__c, Vendor__c from
                           Equipment__c where Aircraft__c = :aircraftID AND
                           (ATA__c = '23' or ATA__c = '25' or ATA__c = '31' or ATA__c = '32'
                           or ATA__c = '34' or ATA__c = '39' or ATA__c = '70' or ATA__c = '22')
                           Order By ATA__c Asc]; 
                          
        } 
          
        return Equipment;
    }

 

and this is the VF page one

 

 <apex:pageBlockSection title="Equipment">
                         
         <apex:pageBlockTable value="{!Equipment}" var="equip">
            <apex:column value="{! equip.ATA__c}"/>
            <apex:column value="{! equip.Description__c}"/>
            <apex:column value="{! equip.Vendor__c}"/>
            <apex:column value="{! equip.Part_Number__c}"/>
        
       </apex:pageBlockTable>   

 

Thanks in advance

S.Aj

 

willardwillard

you'll need a wrapper class

 

 

public class myController {
public class EquipmentWrapper {
public Equipment__c equipment {get;set;}
public integer count {get;set;}
}
                           
 
public List<EquipmentWrapper> getEquipment(Aircraft__c aircraft) {
 
List<Equipment__c> Equipment = new List<Equipment__c>();
       if (aircraft!=null)
        {
            Id aircraftID = aircraft.ID;
            Equipment = [select id, ATA__c, Description__c, Part_Number__c, Serial_Number__c, Vendor__c from 
                           Equipment__c where Aircraft__c = :aircraftID AND 
                           (ATA__c = '23' or ATA__c = '25' or ATA__c = '31' or ATA__c = '32' 
                           or ATA__c = '34' or ATA__c = '39' or ATA__c = '70' or ATA__c = '22')
                           Order By ATA__c Asc];  
}
 
List<equipmentwrapper> wrappers = new list<equipmentwrapper>();
for (equipment__c e : equipment) {
// pseudocode from this point
if (previousdescription == currentdescription) {
wrapper.count++;
} else {
wrapper = new equipmentwrapper();
wrapper.equipment = e;
wrappers.add(wrapper);
}
}
 
return wrappers;
}

 

 

 

On a side note, how are you passing a variable into your controller method?  I thought this wasn't allowed.

SjaleelSjaleel

Its been awhile since I posted this, but couldn't look at it, anyhow I just couldnt make out his wrapper function works.

On the side note it's not a controller method, I guess the naming of my function got confused, anyhow here's the code again...

public with sharing class AircraftController {

    private final Aircraft__c parentAC;
    private List<Aircraft_Eligible_Event__c> ACEligible_Event= new List<Aircraft_Eligible_Event__c>();
   
    private List<Equipment__c> Equipment = new List<Equipment__c>();
  
    public List<Constituent_Assembly__c> ConstAssemb = new List<Constituent_Assembly__c>();
    public List<Constituent_Assembly__c> ConstAssembEngine = new List<Constituent_Assembly__c>();
    public List<Constituent_Assembly__c> ConstAssembGear = new List<Constituent_Assembly__c>();
    public List<Constituent_Assembly__c> ConstAssembApu = new List<Constituent_Assembly__c>();
    
    private final Lease__c Lease;
    private final Operator__c Operator;
   
    private ID parentAC_ID;
    private ID ACEligible_Event_ID;
    private ID Lease_ID;
    private ID OperatorID;
   
    public String email {get;set;}
   
    public class EquipmentWrapper {

        public Equipment__c equipment {get;set;}

        public integer count {get;set;}

 

    }
 
    public AircraftController () {
   
        List<Aircraft__c>   Ac_spec = [select id, Aircraft_Type__c, Assigned_To__c, Country_Of_Registration__c,
                                                  CSN__c, Cycles_Since_Last_C_Check__c, Lease__c,Approach_Landing_Cat__c,
                                                  Number_of_engines__c, Registration_Number__c,ETOPS__c,Line_Num__c,
                                                  Time_Remaining_To_Check__c,TSN__c, Aircraft_Variant__c,
                                                  Auxiliary_Tank_Capacity_Gallons__c, Auxiliary_Tank_Capacity_Kilograms__c,
                                                  Auxillary_Tank_Capacity_Pounds__c, Maximum_Landing_Weight_Max__c,
                                                  Maximum_Landing_Weight_Operational__c, Maximum_Landing_Wt_Purchased_Leased__c,
                                                  Maximum_Operational_Take__c, Maximum_Take_Off_Wt_Max_Design__c,
                                                  Maximum_Take_Off_Weight_Operational__c, Maximum_Zero_Fuel_Wt_Max_Design__c,
                                                  Maximum_Zero_Fuel_Wt_Operational__c, Maximum_Zero_Fuel_Wt_Purchased_Leased__c,
                                                  Standard_Fuel_Capacity_Gallons__c, Standard_Fuel_Capacity_KG__c,
                                                  Standard_Fuel_Capacity_Pounds__c
                                             from Aircraft__c where id =  :ApexPages.currentPage().getParameters().get('id')];
                                                                                                         

    
    
     Equipment = EquipmentList(parentAC);
   }
   

   
     public List<Equipment__c> EquipmentList(Aircraft__c aircraft)
    {
        List<Equipment__c> Equipment = new List<Equipment__c>();
       if (aircraft!=null)
        {
            Id aircraftID = aircraft.ID;
            Equipment = [select id, ATA__c, Description__c, Part_Number__c, Serial_Number__c, Vendor__c from
                           Equipment__c where Aircraft__c = :aircraftID AND
                           (ATA__c = '23' or ATA__c = '25' or ATA__c = '31' or ATA__c = '32'
                           or ATA__c = '34' or ATA__c = '39' or ATA__c = '70' or ATA__c = '22')
                           Order By ATA__c Asc]; 
                          
        } 
          
        return Equipment;
    }
   
    public List<Equipment__c> getEquipment(){
        integer i;
      
        List<equipmentwrapper> wrappers = new list<equipmentwrapper>();

        for (Equipment__c e : Equipment) {
           

            if (e.(i-1) == e.(i)) {

                    wrappers.(i++);

            } else {

            List<equipmentwrapper>   wrapper = new list<equipmentwrapper>();

                wrapper.equipment = e;

                wrappers.add(wrapper);

            }

        }

         return wrappers;

    }
          
    public PageReference sendPdf() {
    
    PageReference pdf = Page.InvoiceGenerator;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',parentAC.id);
 
    // the contents of the attachment from the pdf
    Blob body;
 
    // returns the output of the page as a PDF
    body = pdf.getContent();
 
   
 
    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.setContentType('application/pdf');
    attach.setFileName('AcSpecSheet.pdf');
    attach.setInline(false);
    attach.Body = body;
 
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses(new String[] { email });
    mail.setSubject('Maintenance Reserve Invoice');
    mail.setHtmlBody('Here is the email you requested! Check the attachment!');
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
 
    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
 
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with Invoice sent to '+email));
 
    return null;
 
  }

}

 

I just couldnt make it work wonder what is wrong?

Thanks in advance

S.Aj