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
Mahendiran JayavarmaMahendiran Jayavarma 

Sum the checked rows only

Hi,

 

I wants to sum the billable amount for checked rows only when clicking generate button.

 

 

 

 

 

Controller:

 

public class ActivityController 
{

    public PageReference Search() {
    return null;
        }

Task Task;

public Task getTask() {
      if(Task == null) Task = new Task ();
      return Task ;
   }

    Public Task[] getActivities()
    { 
      
   
      return [Select id, subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task];
    }


 
}

Apex Code:

 

 

<apex:page controller="ActivityController"  >
 <apex:sectionHeader title="Invoice Generate" />

 <apex:form >
<apex:pageBlock >

<apex:pageBlockSection title="Search Task" columns="4" >


<apex:inputField id="Taskstatus" value="{!Task.status}" style="width:150px;"/> 

<apex:commandButton value="Search" action="{!Search}"/>


</apex:pageBlockSection>
<apex:pageBlockSection title="Search Result" columns="1" >
<apex:pageBlockTable value="{!Activities}" var="a" width="750">
  <apex:column >
                        <apex:facet name="header">Select</apex:facet>
                        <apex:inputCheckbox value="{!a.Id}" />
                </apex:column>

<apex:column value="{!a.subject}" rendered="true"/>
<apex:column value="{!a.owner.name}"/>
<apex:column value="{!a.Billable_Hrs__c}"/>
<apex:column value="{!a.Rate_Hrs__c}"/>
<apex:column value="{!a.Billable_Amount__c}"/>
</apex:pageBlockTable>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Generate"/>
</apex:pageBlockButtons>
</apex:pageBlock></apex:form>
</apex:page>

 

 

Help me....

 

Thanks,

 

Mahendiran

DharmeshDharmesh

you can write javascript function

 

function getCheckedRows(){

var obj = document.forms[0].elements;

var checkedIds;

for(var i=0;i<obj.lenght;i++){

if(obj.type=='checkbox' and obj.checked='true'){

checkedIds=checkedIds+"~";

}

}

document.forms[0].ids.value=checkedIds;

}

 

on 

 

<apex:inputCheckbox value="{!a.Id}" onclick="getCheckedRows()" />
define one hidden variable 
<apex:hidden name="ids" value="{!selectedIds}" />
now in controller define one varialble
private selectedIds{get;set}

so when you submit the form you will have all the ids checked on page so you can write the logic to sum the selected ids.