I have a problem with making a dynamic table component that displays selected sObject
fields with specified header values.
The very first idea was to supply the component with an apex:attrubite
of type Map
, containing a key-value pairs for column headerValue
and sObject
field name correspondingly. Then use apex:repeat
to iterate through the collection and add appropriate headers and apex:outputField
just like that:
Component
<apex:attribute name="collection" description="..." type="sObject[]" assignTo="{!sObjectCollection}"/>
<apex:attribute name="fields" description="..." type="Map<String,String>" assignTo="{!fieldsMap}"/>
<apex:pageBlockTable value="{!sObjectsCollection}" var="collectionItem">
<apex:repeat value="{!fieldsMap.keySet()}" var="key">
<apex:column headerValue="{!key}">
<apex:outputField value="{!collectionItem.get(fieldsMap.get(key)}"/>
</apex:column>
</apex:repeat>
</apex:pageBlockTable>
Controller
public List<sObject> sObjectsCollection{ get; set; }
public Map<String, String> fieldsMap { get; set; }
But I get the error: Unsupported type Map<String,String> encountered
.
I'm sure there is some better approach to get desired result.
I have also tried to get the
headerValues
from one String
and the field names from another but then I don't know how to assign a proper headerValue
to specific field name. Any ideas?