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 

get row index from dynamic table

Hi,

 

I've created a dynamic table which allows you to add rows which contain custom fields. Once the save button is clicked all the rows are inserted at once.

 

I'm wanting to add a 'delete row' button on each row.

 

My problem is that I need to be able to pass the row index to the remove method in the apex code.

 

Does anyone have any examples of this?

 

Many thanks in advance

 

Ezmo

kiranmutturukiranmutturu

for the delete command button add a param tag and send the id of the button click to the controller property then you can easily split the id and get the index of the button u clicked.. then u can delete the row from the list and rerender the same list to view the result.....

 

hope you got the point

EzmoEzmo

Thank you for your reply :)

 

Could you show me an example of the page and apex script please?

 

I've been struggling with the apex code part.

 

Many thanks again.

 

Ezmo

Shashikant SharmaShashikant Sharma

You need to write a wrapper class like this

 

public class wrapperTableItems{

 

public Integer index { get ;

                                      set ;

                                   }

public object__c obj {get;set;}

public wrapperTableItems(Integer index , Object__c obj)

{

this.index = index;

        this.obj = obj;

}

 

}

 

 

Add a List<wrapperTableItems> in your main class like 

List<wrapperTableItems> listWrapper = new List<wrapperTableItems> ();

 

add items in list with proper index , when ever new item added index should be listWrapper.size() and when ever you delete any item refresh index of all items.

 

VFP :

Use this list of wrapperTableItems class to show pageblock table

 

kiranmutturukiranmutturu

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

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

</apex:commandbutton>

 

 

in the class you are going to get the id in a property like this  

public string DelRec{get;set;}                       

 u r going to get the delrec value as 'page:form:pgb:0:oppanel'...this is the button id that u are going to get in to the class...so u can split the id and get the index.....

 

hope you got it

lingannalinganna

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

what is meaning  SPD.