You need to sign in to do that
Don't have an account?
Indranil Deria 7
How can I add a new row in existing table by clicking on button ?
Hi,
I want to add a new row in a table which is generated dynamically and newly created row automatically mapped with the table.
For Example:
I have one custom object "Sample" and table look like: -
For adding row in to the table I have written custom controller but that doesn’t work for, the issue is the table is generated dynamically, I can't manage the visualforce page and controller's tables values.
ex:
<apex:pageBlockTable value="{!selected}" var="a" id="table">
</apex:pageBlockTable>
How can I pass the Visualforce table value into apex controller?
I want to add a new row in a table which is generated dynamically and newly created row automatically mapped with the table.
For Example:
I have one custom object "Sample" and table look like: -
For adding row in to the table I have written custom controller but that doesn’t work for, the issue is the table is generated dynamically, I can't manage the visualforce page and controller's tables values.
ex:
<apex:pageBlockTable value="{!selected}" var="a" id="table">
</apex:pageBlockTable>
How can I pass the Visualforce table value into apex controller?
refer this...
https://developer.salesforce.com/forums/?id=906F0000000963NIAQ
let me know if it helps..
Thanks,
Jessie.
I have already gone through that link.
The actual requirement is creating new record while the user is in mass edit page(editing mode), Please check my previously uploaded screenshot you will easily understand the requirement.
Bellow mention is the code which I have Implemented earlier.
Page:
<apex:pageBlock>
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
<apex:commandButton id="cmdAdd" value="+" action="{!addRows}" reRender="out1"/>
<apex:param name="rowIndex" value="{!rowNum}" />
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!Samp}" var="a" rows="{!rows}" >
<apex:column headerValue="Name">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Test Application">
<apex:inputField value="{!a.Test_Application__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute A">
<apex:inputField value="{!a.Test_Attribute_A__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute B">
<apex:inputField value="{!a.Test_Attribute_B__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute C">
<apex:inputField value="{!a.Test_Attribute_C__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute D">
<apex:inputField value="{!a.Test_Attribute_D__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
Controller:
public with sharing class RowsController{
public integer rows{ get; set; }
public List<Sample__c> Samp{ get; set; }
public Integer rowNum{ get; set; }
string Name = '';
string Test_Application__c = '';
string Test_Attribute_A__c = '';
string Test_Attribute_B__c = '';
string Test_Attribute_C__c = '';
string Test_Attribute_D__c = '';
public RowsController() {
CGSS = new List<CG_Sample_Selection__c>();
rows = 3;
getName();
getTest_Application__c();
getTest_Attribute_A__c();
getTest_Attribute_B__c();
getTest_Attribute_C__c();
getTest_Attribute_D__c();
filterRows();
}
public void filterRows(){
for(integer i=1;i<4;i++){
Name = 'null';Test_Application__c = 'null'; Test_Attribute_A__c = '';Test_Attribute_B__c = '';Test_Attribute_C__c = '';Test_Attribute_D__c = '';
Sample__c ss = new Sample__c(rows,Name,Test_Application__c,Test_Attribute_A__c,Test_Attribute_B__c,Test_Attribute_C__c,Test_Attribute_D__c);
Samp.add(ss);
}
}
public void addRows(){
rows = rows + 1;
Sample__c ss = new Sample__c(rows,Name,Test_Application__c,Test_Attribute_A__c,Test_Attribute_B__c,Test_Attribute_C__c,Test_Attribute_D__c);
Samp.add(ss);
}
public class Sample__c{
public integer rowCount{ get; set; }
public string Name{ get; set; }
public string Test_Application__c{ get; set; }
public string Test_Attribute_A__c{ get; set; }
public string Test_Attribute_B__c{ get; set; }
public string Test_Attribute_C__c{ get; set; }
public string Test_Attribute_D__c{ get; set; }
public Sample__c(integer i,string str1,string str2,string str3,string str4,string str5,string str6){
this.rowCount = i;
this.Name = str1;
this.Test_Application__c = str2;
this.Test_Attribute_A__c = str3;
this.Test_Attribute_B__c = str4;
this.Test_Attribute_C__c = str5;
this.Test_Attribute_D__c = str6;
}
}
}
in this line u used "out1" id which u dint refer anywhere in ur code...
to my guess,include id in this
"<apex:pageBlockTable value="{!Samp}" var="a" rows="{!rows}" >"..
let me know if it works!
(for.ex:<apex:pageblock id="out1").it means u are asking the pageblock to refresh again.
to ur scenario,try like this...
<apex:pageBlock>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
<apex:commandButton id="cmdAdd" value="+" action="{!addRows}" reRender="out1"/>
<apex:param name="rowIndex" value="{!rowNum}" />
<apex:variable var="rowNum" value="{!rowNum+1}"/>
<apex:pageBlock id="out1">
<apex:pageBlockTable value="{!Samp}" var="a" rows="{!rows}" >
<apex:column headerValue="Name">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Test Application">
<apex:inputField value="{!a.Test_Application__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute A">
<apex:inputField value="{!a.Test_Attribute_A__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute B">
<apex:inputField value="{!a.Test_Attribute_B__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute C">
<apex:inputField value="{!a.Test_Attribute_C__c}"/>
</apex:column>
<apex:column headerValue="Test Attribute D">
<apex:inputField value="{!a.Test_Attribute_D__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>