How to reset/order of the index after user deletes the row?
In the screen shot, I have 4 rows 1,2,3,4 and I deleted row #3
and when I try to click on Add More Row
then instead of getting row number 3
I got the row number 4
<apex:outputPanel id="accountHead">
<apex:variable value="{!0}" var="rowNum"/>
<apex:pageBlockSection columns="1" title="Adding Multiple Accounts" id="thePbs" collapsible="False">
<apex:pageBlockTable value="{!waAccList}" var="eachRecord">
<apex:column headerValue="Action">
<apex:commandLink value="Remove" style="color:red" action="{!removeRowFromAccList}" rendered="{!rowNum > 0}" rerender="accountHead" immediate="true" >
<apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum + 1}"/>
</apex:column>
<apex:column headerValue="Row" rendered="true" headerClass="colHeadr">
<div class="colHeadr"><apex:outputText value="{!eachRecord.index +1}"/> </div>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputText value="{!eachRecord.record.selectedDay}" required="false"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="Add More" action="{!addNewRowToAccList}" rerender="accountHead" Status="status" />
</apex:outputPanel>
Controller:
public Integer rowToRemove {get;set;}
public void removeRowFromAccList()
{
waAccList = removeRowToAccountList(rowToRemove, waAccList);
}
public void addNewRowToAccList()
{
waAccList = addNewRowToAccList(waAccList);
system.debug('waAccList >>>' + waAccList );
}
public List<WrapperpaAccountList> addNewRowToAccList(List<WrapperpaAccountList> waAccObjList)
{
WrapperpaAccountList newRecord = new WrapperpaAccountList();
mycustomClass newAccountRecord = new mycustomClass();
newRecord.record = newAccountRecord;
newRecord.index = waAccObjList.size(); //<<<<<reset order??
waAccObjList.add(newRecord);
return waAccObjList;
}