How to make summary Column.How to calculate Sum of a column.

Hi
I have a af:table that displays information about Employee vacation. I want to sum the value of the column "ActualNumberOfDays".
Here is the table.

I will Explain how I calculated the total of the "Acutal days" column.
1- I Created a readonly view based on Query
SELECT     v_emv.ID emv_id,     v_emp.EMP_ID emp_id,     v_emp.EMP_NAME_AR ar_name_full,     v_emp.EMP_NUM,     v_vat.NAME_AR,     v_emv.START_DATE,     v_emv.END_DATE,     v_emv.NUMBER_OF_DAYS,     v_set.ACTUAL_END_DATE set_end_date,     v_emv.HOLIDAYS,     v_emv.VACATION_STATUS,     v_set.ACTUAL_NUMBER_OF_DAYS - NVL(v_set.ACTUAL_HOLIDAYS, 0) - NVL(v_set.MISSION_DAYS, 0) actual_number_of_days 
FROM     HRS_V_EMP_BASIC_INFO v_emp,     HRS_V_EMP_VACATIONS v_emv,     HRS_V_VACATION_TYPES v_vat,     HRS_V_EMP_VACATION_SETTLEMENTS v_set WHERE     v_emv.EMP_ID = v_emp.EMP_ID AND v_set.EMV_ID(+) = v_emv.ID AND v_emv.VAT_ID = v_vat.ID 

 2- in a managed bean , Add attribute  private int totalVacationDays; and in the accessor write these this code

  public int getTotalVacationDays() {
        totalVacationDays = 0;
        oracle.jbo.domain.Number total;
        int rowcount = 0;
        DCBindingContainer bc =
            (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding iter =
            bc.findIteratorBinding("empVacations1Iterator");
        iter.setRangeSize(-1);
        Row[] rows = iter.getAllRowsInRange();
        if (rows == null) {
            return 0;
        }
        rowcount = rows.length;
        for (int i = 0; i < rowcount; i++) {
            Row currentRow = rows[i];
            if (currentRow != null) {
                total =
                        (oracle.jbo.domain.Number)currentRow.getAttribute("ActualNumberOfDays");
                if (total != null) {
                    totalVacationDays += total.intValue();
                }
            }
        }
        return totalVacationDays;
    }

3- the last step is to add an af:outputText in somewhere in your page and set the value of this outputtest to the attribue "totalVacationDays" in the bean.Example : #{mybean.totalVacationDays}
and set the partialTriggers property of the outputtext to be the table that contains the column that you want to sum. This will help in case the user adds some filer on the data.



Comments

Popular posts from this blog

Another user has changed the row with primary key oracle.jbo.Key[12 ].

Working With File Throgh WebUtill

Reading From File