+ Start a Discussion

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}"/>
<Div align="right">
<apex:inputText value="{!num}"/>
<apex:commandButton value="Add rows" action="{!add_rows}"/>
<apex:pageBlockTable value="{!PLIC}" var="pli" id="table">
<apex:column headerValue="Inventory">
<apex:inputField value="{!pli.INV_Name__c}"/>
<apex:column headerValue="Item">
<apex:inputField value="{!pli.ITEM__c}"/>
<apex:column headerValue="Qty">
<apex:inputField value="{!pli.PO_Qty__c}"/>
<apex:column headerValue="Unit Price">
<apex:inputField value="{!pli.Item_Unit_Price__c}"/>
<apex:column headerValue="Line Value">
<apex:inputField value="{!pli.PO_LINE_VALUE_N__c}"/>



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');
return home;



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





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

Abhay AroraAbhay Arora



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