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
vjaivjai 

Dynamically inserting rows

Hi SF Team,

 

I've written an VF Page to enter the child object data of a Master Detail relationship for n rows

 

Is there a way to dynamically create a row after the last record is entered rather than specifying the no of rows beforehand.Would any attribute like onclick or on dbclick be helpful.

 

Below is the code.Please advice how to achieve it...

 

<apex:page controller="multiitemsInsert">
<apex:form >
<apex:sectionHeader title="POLINEITEMS" subtitle="AddPOITEMS" />
<apex:pageBlock title="Add row Dynamically" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save_close}"/>
</apex:pageBlockButtons>
<Div align="right">
<apex:inputText value="{!num}"/>
<apex:commandButton value="Add rows" action="{!add_rows}"/>
</Div>
<br/>
<apex:pageBlockTable value="{!PLIC}" var="pli" id="table">
<apex:column headerValue="Inventory">
<apex:inputField value="{!pli.INV_Name__c}"/>
</apex:column>
<apex:column headerValue="Item">
<apex:inputField value="{!pli.ITEM__c}"/>
</apex:column>
<apex:column headerValue="Qty">
<apex:inputField value="{!pli.PO_Qty__c}"/>
</apex:column>
<apex:column headerValue="Unit Price">
<apex:inputField value="{!pli.Item_Unit_Price__c}"/>
</apex:column>
<apex:column headerValue="Line Value">
<apex:inputField value="{!pli.PO_LINE_VALUE_N__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>


AddrowController:-

 

public class multiitemsInsert {

{
public integer num { get; set; }
public List<PO_LINE_ITEM__c> PLIC {get; set;}
public multiitemsInsert()
{
PLIC = new List<PO_LINE_ITEM__c>();
PLIC.add(new PO_LINE_ITEM__c());
}
public PageReference add_rows() {
for(integer i=0;i<num ;i++)
{
PLIC.add(new PO_LINE_ITEM__c());
}

return null;
}
public PageReference save_close()
{ insert PLIC;
PageReference home = new PageReference('/a06/o');
home.setRedirect(true);
return home;
}
}

 

bob_buzzardbob_buzzard

I've written a couple of blog posts on this topic:

 

http://bobbuzzard.blogspot.co.uk/2011/03/edit-parent-and-child-records-with.html

http://bobbuzzard.blogspot.co.uk/2011/04/edit-parent-and-child-records-with.html

 

Its based on accounts and contacts, but should be straightforward to adapt.

Abhay AroraAbhay Arora

http://php-salesforce.blogspot.in/2012/06/wrappers-in-visualforce-and-apex.html

 

Above will help you basically you can use wrapper with some button on that to populate the new row