public class ProductList {
public String name {set;get;}
public Integer quantity {set;get;}
public Decimal price {set;get;}
public Boolean tax {set;get;}
public Boolean flag {Set;get;}
public Decimal total {set;get;}
public Decimal cost {set;get;}
public Decimal taxamount{set;get;}
}
public class ProductExample {
public List<ProductList> products {Set;get;}
public Integer rowid {set;get;}
public ProductExample(){
products=new List<ProductList>();
addMore();
}
public void submit(){
}
public void getData(){
String pname=products.get(rowid).Name;
ProductData__C p=[select Name,Tax__c,Price__C from ProductData__c where
name=:pname limit 1];
products.get(rowid).price=p.price__c;
products.get(rowid).tax=p.tax__c;
}
public void add(){
ProductList p=products.get(rowid);
if(rowid<products.size())
products.add(rowid+1,p);
else
products.add(p);
}
public void deleteRow(){
products.remove(rowid);
}
public void addMore(){
for(Integer i=0;i<=4;i++){
ProductList pl=new ProductList();
products.add(pl);
}
}
public void reset(){
products.clear();
addMore();
}
}
<apex:page
controller="ProductExample" id="page">
<script>
function getRow(myid){
var rowid=myid.split(':');
document.getElementById('page:fm:hidden').value=rowid[4];
}
function callme(myid){
getRow(myid);
rowData();
}
function getData(myid){
var rowid=myid.split(':');
var
price=document.getElementById('page:fm:pb:pbt:'+rowid[4]+':price').value;
var
quantity=document.getElementById('page:fm:pb:pbt:'+rowid[4]+':quantity').value;
var total=price*quantity;
document.getElementById('page:fm:pb:pbt:'+rowid[4]+':cost').value=total;
}
</script>
<apex:form id="fm">
<apex:actionFunction name="rowData"
action="{!getData}" reRender="pb" />
<apex:inputHidden value="{!rowid}" id="hidden"
/>
<apex:pageBlock title="ProductList"
id="pb" >
<apex:pageBlockTable
value="{!products}" var="a" id="pbt">
<apex:column >
<apex:inputCheckBox
value="{!a.flag}" />
<apex:facet
name="header"><apex:inputCheckbox />
</apex:facet>
</apex:column>
<apex:column
headerValue="Product Name">
<apex:inputText
value="{!a.name}" size="10" id="name"
onchange="callme(this.id)" />
</apex:column>
<apex:column
headerValue="Price">
<apex:inputText
size="4" value="{!a.price}" id="price" />
</apex:column>
<apex:column
headerValue="Quantity">
<apex:inputText
size="4" value="{!a.quantity}" id="quantity"
onchange="getData()" />
</apex:column>
<apex:column
headerValue="Tax">
<apex:inputCheckbox
value="{!a.tax}" />
</apex:column>
<apex:column
headerValue="Cost">
<apex:inputText
size="4" value="{!a.cost}" id="cost" />
</apex:column>
<apex:column
headerValue="TaxAmount">
<apex:outputText
value="{!a.taxAmount}" />
</apex:column>
<apex:column
headerValue="Total">
<apex:outputText
value="{!a.total}" />
</apex:column>
<apex:column
headerValue="Action">
<apex:commandButton
value="Add" id="b1"
onclick="getRow(this.id)"
action="{!add}"/>
<apex:commandButton
value="Del" id="b2" onclick="getRow(this.id)"
action="{!deleteRow}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons location="bottom">
<apex:commandButton
value="AddMore" action="{!addMore}" />
<apex:commandButton
value="Submit" action="{!submit}" />
<apex:commandButton
value="Reset" action="{!reset}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
No comments:
Post a Comment