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
asadimasadim 

Removing rows from a dataList

Hi,

 

If I have a dataList that is populated using an array that is defined by the controller, how can I have a button on each row for deleting that row? When the button on row x is pressed the corresponding entry from the array should be removed as well. I have something like this but it doesn't work:

 

 

<apex:dataList value="{!myArray}" var="f" id="myList"> <apex:outputText value="{!f}"/> <apex:outputPanel onclick="removeJS({!f});" styleClass="btn"> Remove </apex:outputPanel> </apex:dataList> ... <apex:actionFunction action="{!removeFromArray}" name="removeJS" rerender="myList"> <apex:param name="firstParam" assignTo="{!valueToRemove}" value=""/> </apex:actionFunction>

 

*** CONTROLLER ***

// the member variable valueToRemove does not get updated when the JS function is called

 

 This is what I have and I think I know why it doesn't work. If you got an idea please go ahead and present. Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
ShikibuShikibu
I think that a code sample I posted, using a wrapper for the list elements, should be adaptable to your problem.

All Answers

ShikibuShikibu
I think that a code sample I posted, using a wrapper for the list elements, should be adaptable to your problem.
This was selected as the best answer
asadimasadim
Thanks. That's definitely a good idea but I'm wondering if there's another way that doesn't require creating wrappers.
bob_buzzardbob_buzzard

Here's my method of doing this, adapted for your situation:

 

 

 

apex:dataList value="{!myArray}" var="f" id="myList">

<apex:outputText value="{!f}"/>

<apex:commandLink action="{!removeFromArray}" value="Remove" rerender="myList">

<apex:param name="delete" assignTo="{!valueToRemove}" value="{!f}"/>

</apex:commandLink>

</apex:dataList>

 So you have a property called valueToRemove in your controller, and your removeFromArray method locates the array entry with the value 'valueToRemove' and deletes it from the array.

 

Message Edited by bob_buzzard on 11-09-2009 02:57 AM
asadimasadim
Perfect! That did it. Thanks!