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

Dynamic table in VF

Can anybody help with sample code for creation n manipulation of dynamic table in VF.

-add row

-add sub row

-save user inputs in the new row

-delete row.

Jeff SJeff S
I am very new at visualforce/apex but my first app needed to do about the same thing you are asking about.  The only thing that isn't in there is the delete.  Since I transfer to this page from a related list in an existing object I just use the standard checkboxes and delete.
Visualforce Page Code:
<apex:page controller="AssembyListComponentPrice" tabStyle="Assembly__c" sidebar="false" >

 <apex:pageBlock title="Edit Components for:  {!Assembly.Assembly_Number__c}" >
     <b>Title:  </b>{!Assembly.Basic_Description__c} 

 <apex:form >
   <apex:pageBlock title="Component Pricing Edit">
   <apex:pageBlockButtons >
     <apex:commandButton value="Save"  action="{!save}"  rerender="rows" status="outStatus"/>
     <apex:commandButton value="Add"   action="{!add}"   rerender="rows" status="outStatus"/>
     <apex:commandButton value="Reset" action="{!reset}" rerender="rows" status="outStatus" 
      immediate="true" />
     <apex:commandButton value="Back to Assembly" action="{!toAssembly}" rerender="rows" status="outStatus" 
      immediate="true" />
     <apex:actionStatus startText="(.................working.................)" stopText="" id="outStatus" onstop="Reset"/>


   <apex:pageBlockTable border="1" cellpadding="6" value="{!components}" var="a" id="rows" > 
      <apex:column ><apex:inputField value="{!}" required="true"/>
          <apex:facet name="header">Part Number</apex:facet>
      <apex:column ><apex:inputField value="{!a.Description__c}" required="false"/>
          <apex:facet name="header">Description</apex:facet>
      <apex:column ><apex:inputField value="{!a.Qty_Per_Assembly__c}" required="false"/>
          <apex:facet name="header">Qty Per Assembly</apex:facet>
      <apex:column ><apex:inputField value="{!a.List_Price__c}" required="false"/>
          <apex:facet name="header">List Price</apex:facet>
      <apex:column ><apex:inputField value="{!a.Sell_Price_Multiplier__c}" required="false" />
          <apex:facet name="header">Sell Price Multiplier</apex:facet>
      <apex:column ><apex:outputField value="{!a.Selling_Price_Each__c}" id="sp"/>
                <apex:facet name="header">Sell Price Each</apex:facet>
      <apex:column ><apex:inputField value="{!a.Cost_Multiplier__c}" required="false"/>
          <apex:facet name="header">SEC Cost Multiplier</apex:facet>
      <apex:column ><apex:outputField value="{!a.Cost_Each__c}" id="ce"/>
                <apex:facet name="header">SEC Cost Each</apex:facet>



  Custom Class:
public class AssembyListComponentPrice {

        public List<Component__c> componentList;  // list of components to appear in the multi-line
        public PageReference reset() {
            componentList = [select Assembly__c, Qty_Per_Assembly__c, Name, Id, Description__c, List_Price__c, 
                    Sell_Price_Multiplier__c, Cost_Multiplier__c, Selling_Price_Each__c, Cost_Each__c, 
                               from Component__c
                               where Assembly__c = :System.currentPageReference().getParameters().get('id')
                               order by First_Position__c];
            return null;
        public List<Component__c> getComponents() {
            if(componentList == null) reset(); 
            return componentList;
        public void setComponents(List<Component__c> Components) {
            componentList = Components;
        public PageReference save() {
            upsert componentList;
            return null;
        public PageReference toAssembly() {
            PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
            return pageRef;

        public PageReference add() {
            componentList.add(New Component__c(Assembly__c = ApexPages.currentPage().getParameters().get('id'),
                              Name = 'New Component'));
            return null;

        public Assembly__c getAssembly() {
            return [select Assembly_Number__c, Basic_Description__c from Assembly__c 
                     where id = :ApexPages.currentPage().getParameters().get('id')]; 


Message Edited by Jeff S on 06-29-2008 08:30 PM

Message Edited by Jeff S on 06-29-2008 08:31 PM
Thanks Jeff

Hi Jeff,


I want the same thing, but am not able to understand your object hierarchy . will you please tell me what are the objects you used and their fields in this example and if any relation between two objects.




Neeru Nagpal