Outside of a data table, a cascading select list (or drop down) is done generically like so:
<apex:selectList value="{!parentValue}">
<apex:selectOptions value="{!ParentOptions}" />
<apex:actionSupport event="onchange" rerender="children">
</apex:selectList>
<apex:outputPanel id="children"
<apex:selectList value="{!childValue}">
<apex:selectOptions value="{!ChildOptions}" />
</apex:selectList>
</apex:outputPanel>
Where the controller has the following:
public String parentValue {get; set;}
public String childValue = {get; set;}
public List<SelectOption> getParentOptions() {
List<SelectOption> options = new List<SelectOption>();
for (obj__c obj : [select id, name from obj__c]) {
options.add(new SelectOption(obj.id, obj.name));
}
return options;
}
public List<SelectOption> getParentOptions() {
List<SelectOption> options = new List<SelectOption>();
for (obj2__c obj : [select id, name from obj2__c where obj__c = :parentValue]) {
options.add(new SelectOption(obj2.id, obj2.name));
}
return options;
}
How do you do this in a data table, where a SelectList in one column, when changed, rerenders a dependent SelectList in another column, given that apex:ouputPanel's id can't be dynamically created?
Basically I have a custom object that I wish to display in tabular form and allow the user to edit it. I use on all the String fields of the custom object to allow the user to double click and edit the field. Where there is essentially a picklist of available options for the user to chose from, I use to allow the user to change the option. However, one of these selectList's options will be dependent upon the selection of another SelectList's value. I would not want to refresh the entire data table each time one of the rows selectList's is changed as that would be slow.
<apex:dataTable value="{!objects}" var = "{!o}">
<apex:column>
<apex:selectList value="{!o.parent__c}">
<apex:selectOptions value="{!parentItems}" />
<!-- <apex:actionSupport> -->
</apex:selectList>
</apex:column>
<apex:column>
<apex:selectList value="{!o.dependent__c}">
<apex:selectOptions value="{!depndentItems}" />
</apex:selectList>
</apex:column>
</apex:dataTable>
Thank you.