I have created a table with edit, create and delete options of record. But I have a issue in deleting operation. When am trying to delete the last row of table, all the rows are deleted except the first row. Please provide the solution ?? how can I delete the particular selected record ??
Apex class
public class addRowRemoveRow{
public List<Account> allAccs {get; set;}
public string SelectedAccountId {get; set;}
public static Integer toDelIdent {get; set;}
public addRowRemoveRow(){
allAccs = new List<Account>();
Account acc1 = new Account();
allAccs.add(acc1);
}
public void addRowMethod(){
Account acc1 = new Account();
allAccs.add(acc1);
}
public void removeRowMethod(){
integer count = allAccs.size();
system.debug('size----->'+count);
allAccs.remove(count--);
}
public void saveMethod(){
insert allAccs;
clearMethod();
}
public void clearMethod(){
integer finalCount = allAccs.size();
allAccs.clear();
for(integer i=0;i<finalCount;i++){
Account acc1 = new Account();
allAccs.add(acc1);
}
}
}
VF page
<apex:page controller="addRowRemoveRow">
<apex:form >
<apex:pageBlock id="anyName">
<apex:dataTable value="{!allAccs}" var="Accvariable" cellpadding="4" border="1">
<apex:column headerValue="Action">
<apex:outputLink >Edit</apex:outputLink> |
<apex:outputLink >Del</apex:outputLink>
</apex:column>
<apex:column headerValue="Model">
<apex:inputtext value="{!Accvariable.Name}"/>
</apex:column>
<apex:column headerValue="Version">
<apex:inputtext value="{!Accvariable.Phone}"/>
</apex:column>
<apex:column headerValue="Discount">
<apex:inputtext value="{!Accvariable.website}"/>
</apex:column>
</apex:dataTable>
<apex:pageBlockButtons location="TOP">
<apex:commandButton value="addRow" action="{!addRowMethod}" rerender="anyName" />
<!-- <apex:commandButton value="removeRow" action="{!removeRowMethod}"/>-->
<apex:commandButton value="save" action="{!saveMethod}"/>
<!-- <apex:commandButton value="Clear" action="{!clearMethod}" reRender="anyName" />-->
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>