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
SatheeshDevsinCloudSatheeshDevsinCloud 

Remove Row Dynamically from a Pageblocktable

Hi All,

 

I have a pageblock table in a visualforce page say created for object Opportunity …

 

Inside  the page block table I created another one table for object Product…..

 

I used Map like Map<Oppty,List<Product>> to populate Opportunity values and corresponding product values in to the table

 

and the table is editable to add new values……..

 

In Edit Mode ,I have added “AddRow” link to add new rows in the table and Delete Row link to delete a particular row in the  table….

 

Since I am using using the Map in the page block table I am not able to write a method for “Delete Row” link ...

 

Please anyone suggest..

 

 

Best Answer chosen by Admin (Salesforce Developers) 
BharathimohanBharathimohan

Hi,

 

Try with  wrapper classes.

 

 

 

Regards,

Bharathi

All Answers

Saurabh DhobleSaurabh Dhoble

It would have been much better if you had pasted your code here. However, from what I understand, you need to call the Delete method and pass in the ID of the row you are deleting.

 

That way, you wouldn't need to worry about removing it from the Map. Just delete it using the DELETE keyword, and then rebuild your map and that should fix your issue.

The exact specifics are here

BharathimohanBharathimohan

Hi,

 

Try with  wrapper classes.

 

 

 

Regards,

Bharathi

This was selected as the best answer
SatheeshDevsinCloudSatheeshDevsinCloud

Hey Barathi,

 

Thanks for the suggestion ...

 

Already I had an idea of changing the entire code using wrapper class. Now I have changed using wrapper class , now its working.

 

Thanks

AlibabaAlibaba

Hi Cloud Sticker,

 

I am having a similar issue with a pageblocktable, and wanting to delete a row in the table and rerender it.

 

How did you solve this? When you say wrapper class, does this mean you wrote it in Javascript?

 

Thanks very much in advance.

SatheeshDevsinCloudSatheeshDevsinCloud

Hi Alibaba,

 

I just used the remove() method with the list to remove the selected row.

 

All you have to do is to pass the rownumber of the particular row using apex:param.

 

then in a write a method for deleting the row.

 

public void delRow()
    {
        rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        memberAddList.remove(rowNum);  
    }   

 

 

 

AlibabaAlibaba

CloudSticker,

 

Thanks so much.

 

One last question, how does the Param attribute know the row number? Do you use a wrapper class to store the row number? Is there an easy solution that I'm missing here?

 

Thanks again!

SatheeshDevsinCloudSatheeshDevsinCloud

Hi,

 

Please refer this blog of my friend....

 

http://infallibletechie.blogspot.in/2012/06/dynamically-deleting-rows-in-apex.html

 

cheers,,,