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
BridgetreeBridgetree 

aggregate function in datatable

Hi all....

 

 

               I have a Dynamic data table in which i will have a value in each row. Now i want to perform the addition of these values.

 

The values of row are brought from object of a class.

Description is like this.

I have a table and columns like this

Product name

clean value

No of items

Total

 

So after the total is calculated for each row,

i want to calculate the sum of values in Column.

 

Pls suggest a way for this. I want to display the value.

 

 

 

TheSwamiTheSwami

You should be able to do all of this logic in your controller code (apex).  Apex can total the value and return the result to the VisualForce page.  If you provide the code you have, I could try to give more specifics.

BridgetreeBridgetree

The VisualForce page is like this.

 

<apex:page standardStylesheets="false" showHeader="false" sidebar="false"
 controller="StoreFront" >
<apex:stylesheet value="{!URLFOR($Resource.styles, 'styles.css')}"/>
<h1>Current Orders</h1>
<style type="text/css">
#one {
    width:20px; /* set width here */
    padding-bottom:2em;
}
</style>
<apex:form >
<apex:dataTable value="{!products}" var="pitem" rowClasses="odd,even">
<apex:column headerValue="Product Name">
<apex:outputText value="{!pitem.merchandise.Product_name__c}"/>
</apex:column>
<apex:column headerValue="Clean" width="20">
<apex:outputText value="{!pitem.merchandise.clean__c}"/>
</apex:column>
<apex:column headerValue="#">
<apex:inputText value="{!pitem.count_clean}"/>
<br/>
<apex:commandButton action="{!shop}" reRender="msg" value="Buy" />
</apex:column>
<apex:column headerValue="Total">
<apex:outputText id="msg" value="{!total_clean}"/>
</apex:column>

<apex:column headerValue="Sanitize">
<apex:outputText value="{!pitem.merchandise.sanitize__c}"/>
</apex:column>
<apex:column headerValue="#">
<apex:inputText value="{!pitem.count_sanitize}"/>
<br/>
<apex:commandButton action="{!shop}" reRender="msg1" value="Buy" />
</apex:column>
<apex:column headerValue="Total">
<apex:outputText id="msg1" value="{!total_sanitize}"/>
</apex:column>

<apex:column headerValue="Deodorize">
<apex:outputText value="{!pitem.merchandise.deodorize__c}"/>
</apex:column>
<apex:column headerValue="#">
<apex:inputText value="{!pitem.count_deodorize}"/>
<br/>
<apex:commandButton action="{!shop}" reRender="msg2" value="Buy" />
</apex:column>
<apex:column headerValue="Total">
<apex:outputText id="msg2" value="{!total_deodorize}"/>
</apex:column>

<apex:column headerValue="Dust-Mite">
<apex:outputText value="{!pitem.merchandise.dust_mite__c}"/>
</apex:column>
<apex:column headerValue="#">
<apex:inputText value="{!pitem.count_dustmite}"/>
<br/>
<apex:commandButton action="{!shop}" reRender="msg3" value="Buy" />
</apex:column>
<apex:column headerValue="Total">
<apex:outputText id="msg3" value="{!total_dustmite}"/>
</apex:column>

<apex:column headerValue="Protectant">
<apex:outputText value="{!pitem.merchandise.protectant__c}"/>
</apex:column>
<apex:column headerValue="#">
<apex:inputText value="{!pitem.count_protectant}"/>
<br/>
<apex:commandButton action="{!shop}" reRender="msg4" value="Buy" />
</apex:column>
<apex:column headerValue="Total">
<apex:outputText id="msg4" value="{!total_protectant}"/>
</apex:column>

<apex:column headerValue="Line Total">
<apex:commandButton action="{!shop}" reRender="msg5" value="CALC" />
<br /><br />
<apex:outputText id="msg5" value="{!pitem.linetotal}"/>
</apex:column>

</apex:dataTable>
<br />
<br />
<apex:commandButton action="{!shop}" reRender="total" value="Find Total" />
</apex:form>
<apex:outputPanel id="total">{!message}
<br />
{!messages}

</apex:outputPanel>
<br />

</apex:page>

 

And the Controller is

 

public class StoreFront {

    public Double total_protectant { get; set; }

    public Double total_dustmite { get; set; }

    public Double total_sanitize { get; set; }

    public Double total_deodorize { get; set; }

    public String message { get; set; }
    
    public String messages { get; set; }

    public Double total_clean { get; set; }

    public double clean=0;
    
public PageReference shop() {
total_clean=0;
total_sanitize=0;
total_deodorize=0;
total_dustmite=0;
total_protectant=0;

message = 'Your clean only ';
messages = 'Your order total is';

for (DisplayMerchandise p: products) {
if (p.count_clean > 0) {
clean=p.merchandise.clean__c * p.count_clean;
total_clean=clean;
p.cleanonly += clean;
message += ''+ ' (' + p.cleanonly + ') ';
}

if (p.count_sanitize >0)
{
total_sanitize=p.merchandise.sanitize__c * p.count_sanitize;
}
if (p.count_deodorize >0)
{
total_deodorize=p.merchandise.deodorize__c * p.count_deodorize;
}
if (p.count_dustmite >0)
{
total_dustmite=p.merchandise.dust_mite__c * p.count_dustmite;
}
if (p.count_protectant >0)
{
total_protectant=p.merchandise.protectant__c * p.count_protectant;
}
p.linetotal=total_clean + total_sanitize + total_deodorize + total_dustmite + total_protectant;

}

return null;
}
DisplayMerchandise[] products;
public class DisplayMerchandise {
public MileageTracking__Franchisee__c merchandise { get; set; }
public Decimal count_clean { get; set; }
public Decimal count_sanitize { get; set; }
public Decimal count_deodorize { get; set; }
public Decimal count_dustmite { get; set; }
public Decimal count_protectant { get; set; }
public Double linetotal { get; set; }
public Double cleanonly { get; set
{cleanonly=0;} }
public Double ordertotal { get; set; }
public DisplayMerchandise(MileageTracking__Franchisee__c item) {
this.merchandise = item;
}
}
public DisplayMerchandise[] getProducts() {
if (products == null) {
products = new DisplayMerchandise[]{};
for (MileageTracking__Franchisee__c item :
[SELECT MileageTracking__Product_name__c, MileageTracking__clean__c, MileageTracking__sanitize__c,
MileageTracking__deodorize__c, MileageTracking__dust_mite__c,   MileageTracking__protectant__c
FROM MileageTracking__Franchisee__c]) {
products.add(new DisplayMerchandise(item));
}
}
return products;
}
}

 

 

 

That is where i am fixed up..

Pls find a solution

 

 

Phaniraj N