You need to sign in to do that
Don't have an account?

delete row from table
im unable to get the index of row...see my code
vf page:-
<apex:page controller="t6">
<apex:form >
<apex:pageBlock id="yu">
<apex:variable var="rowNumber" value="{!0}"/>
<apex:pageBlockButtons >
<apex:commandButton value="Add row" action="{!ar}" reRender="yu"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!qe}" var="y">
<apex:column headerValue="index">
<apex:outputText value="{0}">
<apex:param value="{!rowNumber+1}"/>
</apex:outputText>
</apex:column>
<apex:column >
<apex:commandButton value="remove" action="{!remove}" reRender="eee"/>
<apex:param name="index" value="{!rowNumber}" />
</apex:column>
<apex:column headerValue="name">
<apex:inputField value="{!y.name}"/>
</apex:column>
<apex:column headerValue="account" >
<apex:inputField value="{!y.Account__c}" >
<apex:actionSupport event="onchange" action="{!chng}" />
</apex:inputField>
</apex:column>
<apex:column headerValue="contacts">
<apex:selectList size="1" multiselect="false" >
<apex:selectOptions value="{!connames}">
</apex:selectOptions>
</apex:selectList>
</apex:column>
<apex:column headerValue="amount">
<apex:inputField value="{!y.currency__c}"/>
<apex:variable var="rowNumber" value="{!rowNumber+1}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:-
public class t6
{
public List<sales__c> qe {get;set;}
public Integer rowNumber{get;set;}
//Integer inx;
sales__c s;
String t;
public t6()
{
s=new sales__c();
qe=new List<sales__c>();
qe.add(s);
}
public void ar()
{
sales__c s1=new sales__c();
qe.add(s1);
}
public void remove()
{
//qe.remove(1);
//rowNumber = Integer.valueOf(ApexPages.currentPage().getParameters().get('index'));
System.debug(rowNumber);
}
public void chng()
{
sales__c f=new sales__c();
f=qe[qe.size()-1];
t=f.account__c;
}
public List<SelectOption> getConnames()
{
List<SelectOption> allc=new List<SelectOption>();
for(Contact c:[SELECT id,name,email from Contact where Account.Id=:t])
{
allc.add(new SelectOption(c.id,c.name));
}
return allc;
}
}
vf page:-
<apex:page controller="t6">
<apex:form >
<apex:pageBlock id="yu">
<apex:variable var="rowNumber" value="{!0}"/>
<apex:pageBlockButtons >
<apex:commandButton value="Add row" action="{!ar}" reRender="yu"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!qe}" var="y">
<apex:column headerValue="index">
<apex:outputText value="{0}">
<apex:param value="{!rowNumber+1}"/>
</apex:outputText>
</apex:column>
<apex:column >
<apex:commandButton value="remove" action="{!remove}" reRender="eee"/>
<apex:param name="index" value="{!rowNumber}" />
</apex:column>
<apex:column headerValue="name">
<apex:inputField value="{!y.name}"/>
</apex:column>
<apex:column headerValue="account" >
<apex:inputField value="{!y.Account__c}" >
<apex:actionSupport event="onchange" action="{!chng}" />
</apex:inputField>
</apex:column>
<apex:column headerValue="contacts">
<apex:selectList size="1" multiselect="false" >
<apex:selectOptions value="{!connames}">
</apex:selectOptions>
</apex:selectList>
</apex:column>
<apex:column headerValue="amount">
<apex:inputField value="{!y.currency__c}"/>
<apex:variable var="rowNumber" value="{!rowNumber+1}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:-
public class t6
{
public List<sales__c> qe {get;set;}
public Integer rowNumber{get;set;}
//Integer inx;
sales__c s;
String t;
public t6()
{
s=new sales__c();
qe=new List<sales__c>();
qe.add(s);
}
public void ar()
{
sales__c s1=new sales__c();
qe.add(s1);
}
public void remove()
{
//qe.remove(1);
//rowNumber = Integer.valueOf(ApexPages.currentPage().getParameters().get('index'));
System.debug(rowNumber);
}
public void chng()
{
sales__c f=new sales__c();
f=qe[qe.size()-1];
t=f.account__c;
}
public List<SelectOption> getConnames()
{
List<SelectOption> allc=new List<SelectOption>();
for(Contact c:[SELECT id,name,email from Contact where Account.Id=:t])
{
allc.add(new SelectOption(c.id,c.name));
}
return allc;
}
}
i found my mistake, i was clossing command button tag before param tag
thnks for your concern
All Answers
Change this
to
You could see exact same example here : http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html
And a same issue being resolved here: https://developer.salesforce.com/forums/?id=906F000000091JfIAI
Let me knwo if you still face issues.
Thanks
Shashikant
Still getting the Exception
System.NullPointerException: Argument cannot be null.
Error is in expression '{!remove}' in page task6: Class.t6.remove: line 26, column 1
Class.t6.remove: line 26, column 1
Thanks
The blog that i shared is for reference, you could define your structure as your needs.
Thanks
Shashikant
i found my mistake, i was clossing command button tag before param tag
thnks for your concern
Please mark this post as solved so other coudl be benifitted from it.
Thanks
Shashikant