function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vishwa attikerivishwa attikeri 

How to display in order

hi,

I am using wrapper class to display the date in vf but here it works fine but i need to display in ascending order 

can any one please help 

here is my code sample

Public lass finalpay()
{
   public void prepareMap()
   {
        salesPerformanceData = new Map<Date, FRSummaryWrap>();
        List<Time_Card__c> empList = [select name,day__c,date__c,days__c from Time_Card__c where Month__c=:month and Employee__r.name=:emp and Year__c=:year order by date__c ASC];
        for(Time_Card__c emp: empList){
               
            salesPerformanceData.put(emp.Date__c,new FRSummaryWrap(emp.Date__c,amount));
        }
		}
		
		 public List<FRSummaryWrap> getWrapSummaryList(){
        return salesPerformanceData.values();
    }
	
	   
    public class FRSummaryWrap{
    
       public Date tdate{get;set;}
	   
	    public FRSummaryWrap(Date dat,String prunitamt){
             
            tdate = dat;
           }
                    
        }
        }

 Here is my VF page

 <apex:repeat value="{!wrapSummaryList}" var="Wrp">
 
 <tr border="1"> 
 <td  Style="font-family: Arial; font-size: 10pt; font-weight: bold;">{!Wrp.tdate}</td>
</tr>  
 </apex:repeat> 

 

Best Answer chosen by Admin (Salesforce Developers) 
Devendra NataniDevendra Natani

Hi,

 

The wrapper class which you are using, Please create some properties for the following fields

  1. Total_Time_House_Keeping_task__c
  2. Total_Time__c
  3. TotalTime_of_DMM__c
  4. Total_Time_of_Dressing__c
  5. Total_Time_of_Eating__c
  6. Total_Time_of_Mobility__c

Total_Time_TI__c

Then populate this properties by applying the conditions which you are currently doing in totaltime() method. Then finally you will have a wrapper class with all fields values. Use that class on page. 
Please let me know if there is any issue.

Thanks,

Devendra Natani 

 

All Answers

Devendra NataniDevendra Natani

Hi,

 

You are put the data in map using "empList". Map is a un-ordered collection. It will not return the data in same order in which you are putting into that.

 

Instead of using map please try something like that.

 

List<FRSummaryWrap> lstFRSummaryWrap = new List<FRSummaryWrap>();
List<Time_Card__c> empList = [select name,day__c,date__c,days__c from Time_Card__c where Month__c=:month and Employee__r.name=:emp and Year__c=:year order by date__c ASC];
        for(Time_Card__c emp: empList){
lstFRSummaryWrap .add(new FRSummaryWrap(emp.Date__c,amount)); 
}


 public List<FRSummaryWrap> getWrapSummaryList(){
        return lstFRSummaryWrap ;
    }

 

Please let me know if there is any issue.

 

Thanks,

Devendra Natani

Blog

vishwa attikerivishwa attikeri

Hi 

 

Thanks for your suggestion, i am using map here becouse depending on the date im calculating some value please go through the below code once

public PageReference searchAction(){
     
            prepareMap();
            fetchAllData();
    
        return null;
    }

    List< Time_card__c> timecard;

    Map<Date,FRSummaryWrap> salesPerformanceData = new Map<Date, FRSummaryWrap>();    
    
    public void fetchAllData(){
        
        timecard =[select  name,Total_Time_House_Keeping_task__c,Employee__r.Name,Total_Time__c,TotalTime_of_DMM__c,Total_Time_of_Dressing__c,
Total_Time_of_Eating__c,Total_Time_of_Mobility__c,Total_Time_TI__c,Date__c from Time_Card__c where Month__c=:month and Year__c=:year and Employee__r.name=:emp];
        
        totaltime();
       
    }
    
    public void prepareMap(){
        salesPerformanceData = new Map<Date, FRSummaryWrap>();
        List<Time_Card__c> empList = [select name,day__c,date__c,days__c from Time_Card__c where Month__c=:month and Employee__r.name=:emp and Year__c=:year order by date__c ASC];
        for(Time_Card__c emp: empList){
        //String dat=String.valueof(emp.date__c);
        
            salesPerformanceData.put(emp.Date__c,new FRSummaryWrap(emp.Date__c,amount));
        }

              
    } 
  
        

     
    public void totaltime(){
        for( Time_Card__c tc: timecard){
            if(tc.Total_Time_House_Keeping_task__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal1(tc.Total_Time_House_Keeping_task__c.intValue());
                
            }
               if(tc.Total_Time__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal2(tc.Total_Time__c.intValue());
                
            }
             if(tc.TotalTime_of_DMM__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal3(tc.TotalTime_of_DMM__c.intValue());
                
            }
             if(tc.Total_Time_of_Dressing__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal4(tc.Total_Time_of_Dressing__c.intValue());
                
            }
             if(tc.Total_Time_of_Eating__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal5(tc.Total_Time_of_Eating__c.intValue());
                
            }
            if(tc.Total_Time_of_Mobility__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal6(tc.Total_Time_of_Mobility__c.intValue());
                
            }
            
                if(tc.Total_Time_TI__c!=null){            salesPerformanceData.get(tc.Date__c).addtotal7(tc.Total_Time_TI__c.intValue());
                
            }
            
        
        }            
         
    }

 Thanks

Devendra NataniDevendra Natani

You can  keep both map and list. The values which you are updating into map depending on some conditions. You can update the list accordingly as well. The method "getWrapSummaryList()" should return a list and the list should not be driven from a map. 

i.e. map.values() 

 

Please let me know if there is any issue.

 

Thanks,

Devendra Natani

vishwa attikerivishwa attikeri

hi,

 

 

When im going to return the list it will daiplaying date with order, but my calculation part will not come

can u tel, how it will solve

 

Thanks

Devendra NataniDevendra Natani

Hi,

 

The wrapper class which you are using, Please create some properties for the following fields

  1. Total_Time_House_Keeping_task__c
  2. Total_Time__c
  3. TotalTime_of_DMM__c
  4. Total_Time_of_Dressing__c
  5. Total_Time_of_Eating__c
  6. Total_Time_of_Mobility__c

Total_Time_TI__c

Then populate this properties by applying the conditions which you are currently doing in totaltime() method. Then finally you will have a wrapper class with all fields values. Use that class on page. 
Please let me know if there is any issue.

Thanks,

Devendra Natani 

 

This was selected as the best answer
vishwa attikerivishwa attikeri

Hi,

 

when using list it will display the field values for particular date but i need to do some calculation 

for ex: totaltime=calculating all total fields 

and totalunit=totaltime/60

 

and it will display with particular date

 

can you please....

 

Thanks

vishwa attikerivishwa attikeri

Hi,

 

Thanks a lot its working fine