Skip to content

Instantly share code, notes, and snippets.

@ueki-kazuki
Last active April 21, 2017 06:28
Show Gist options
  • Save ueki-kazuki/84c7ea6792a706eaf88f44b6a2150ed4 to your computer and use it in GitHub Desktop.
Save ueki-kazuki/84c7ea6792a706eaf88f44b6a2150ed4 to your computer and use it in GitHub Desktop.
<apex:page controller="DynamicActionController">
<apex:form >
<apex:actionFunction name="refreshResults" reRender="searchResults" status="searchStatus"/>
<apex:dataTable value="{!records}" var="rec" >
<apex:column >
<apex:inputCheckbox value="{!rec.checked}" onchange="return refreshResults()"/>
</apex:column>
<apex:column style="text-align:right;">
<apex:inputText value="{!rec.value}" onchange="return refreshResults()"/>
</apex:column>
</apex:dataTable>
<apex:outputPanel id="searchResults">
<apex:actionStatus id="searchStatus" startText="合計値を再計算しています..."/>
<apex:outputText value="{0, number, ###,###}">
<apex:param value="{!total}"/>
</apex:outputText> 円
</apex:outputPanel>
</apex:form>
</apex:page>
public with sharing class DynamicActionController {
public class MyClass {
public Decimal value {get; set;}
public Boolean checked {get;set;}
public MyClass(Decimal value) {
this.checked = false;
this.value = value;
}
}
public List<MyClass> records {get;set;}
public DynamicActionController() {
this.records = new List<MyClass>();
this.records.add(new MyClass(10000));
this.records.add(new MyClass(2345));
}
public Decimal getTotal() {
Decimal total = 0;
for(MyClass o : this.records) {
if (o.checked) { total += o.value; }
}
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment