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
EzmoEzmo 

Remove row from dynamic list table

Hi there,

 

I've created a dynamic list which renders in a table where a user can add rows, enter data into the fields then click save to insert all the rows.

I am wanting to add the functionality to delete a row that may have been added by mistake.

 

I have got as far as:

public void deleteRow(){
    distribution.remove(0);
}

'distribution' is the name of the list.

 

The problem with this code is that it only removes the row with the index stated in the brackets. I'm wanting it to remove the row that the command button is in.

 

For extra reference here is the code for the table which the list renders in.

 

<apex:pageBlockTable rowClasses="even,odd" value="{!distribution}" var="dist" columns="3">
        
        <apex:column >
            <h1>Venue / Organisation:</h1><br/>
            <apex:inputField value="{!dist.Venue_Organisation__c}"/><p/>
            <h1>Date:</h1><br/>
            <apex:outputField value="{!dist.Date__c}"/>
        </apex:column>
        
        <apex:column >
            <h1>Resource:</h1><br/>
            <apex:outputField value="{!dist.Resource__c}"/><p/>
            <h1>Quantity:</h1><br/>
            <apex:inputField value="{!dist.Quantity__c}"/>
        </apex:column>
        
        <apex:column >
            <apex:commandButton value="remove" action="{!deleteRow}"/>
        </apex:column>          
        
        <apex:facet name="footer">          
                <apex:commandButton value="add" onMouseDown="javascript&colon;afunction()" action="{!addrow}"/>
        </apex:facet>
        
    </apex:pageBlockTable>

 

Many thanks in advance for your help

 

Ezmo

kiranmutturukiranmutturu

use apex:param  and send the index of the record .. and delete that indexed record...

 

 

like this

 

 


<apex:commandButton value="Delete"   action="{!DeleteShipDetail}"  id="btndel" rerender="ShipmentDetailList">

        <apex:param name="ShipIdent" value="{!SPD.id}" assignTo="{!DelRec}"/>

</a[ex:commandbutton>

 

from that id u can get the index of the record .. and u can remove that record...

EzmoEzmo

Hi Kiran,

 

Thank you for your quick reply. I've not passed from a page to a class before, could you show what the apex code would be please?

 

Thanks again

 

Ezmo