+ Start a Discussion

Problems trying to make a general-purpose data grid



We have been trying to create a Visualforce framework which can support the display of the results of any SOQL query - without anything pre-determined at compile time.  


The controller component uses a set of Apex classes, which are instantiated with the following information:

  • The SObject name we want to query
  • The field names we want to query (including relationship fields; e.g. 'Account.Name')
  • The widths of the grid columns on the resulting VF page table 
  • The query clause

All specified by strings.  And then using Database.query() and subsequent SObject.get (fldName) and SObject.getSObject (relpFldName) calls, we can create a matrix of data from the result set.  Note that the number of fields is determined at run-time, and so the number of columns in the resulting dataTable on the VF page is also determined at run-time.

We managed to build this and it works well.  Problems arise, however, trying to get this matrix displayed on the VF page. 


My first approach was to use the <apex:repeat> component, as follows:



<apex:dataTable value="{!myDynamicGrid}" var="myGridRow"> <apex:repeat value="{!myGridRow.columns}" var="myGridCell"> <apex:column width="{!myGridCell.width}"> <apex:outputText value="{!myGridCell.text}"/> </apex:column> </apex:repeat> </apex:dataTable>


But this doesn't even compile - apparently <apex:column> must be a direct child of <apex:dataTable>.


I have tried rolling my own a bit, using a hybrid of Visualforce markup and straight HTML, with no success.


Has anyone out there ever tried something like this?  Is there a way to accomplish this on a VF page, without resorting to ugly hard-coded column components on the VF page?