You need to sign in to do that
Don't have an account?
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!
All Answers
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.