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
damienmagnandamienmagnan 

A table with a variable number of columns

Hi everyone,

I have to build a table that represents an activity summary for a month. That is, I have up to 31 columns for each days in the month and a dozen lines for each type of activity, and for each line and column I have an input field.
Is that possible generate dynamically the column on page load ?

I would like to avoid copying/pasting 31 times the same column and also I would like to avoid creating an accessor method for each column.

It brings my second question : is that possible, in an visualforce "{! }" markup to call methods of the controller by passing the method one or more parameter ?

For example, I'd like a method valueForColumn(Integer index) that returns the value of the column "index" and put one column on my VF page that will be reproduced as much as I need with the value changing depending on the index of the column.

Thanks in advance.
MRietveldMRietveld

Hi, did you have any luck with your problem?

 

I think you could solve part of your problem by using the <apex:PanelGrid> which allows you to use a variable number of columns. But unfortunatunately this component only allows you to outputtext, not input. 

 

I have the same problem, please let me know if you found a solution. 

 

Thanks

 

Marcel

suneilchetlursuneilchetlur

HI ,were you able to find a solution for this problem

I have a similar issue where i need to have multiple columns in the table in visualforce page.The number of columns would depend on certain criterias and should get populated with values from product schedule.

If you have found some solution on how to have variable number of columns pls do respond..

 

Thanks

Suneil

MRietveldMRietveld

Yeah, I found the solution but it involves using stylesheets. What I did was this:

 

In the controller, I used a nested SQL statement to create a two-dimensional list. In the visualforce page I used two nested repeat tags that showed the two dimensions as nested lists. The repeat clauses are wrapped in div tags, and in the stylesheet those tags are positioned within each other. 

 

So, the first div tag (i.e. the first repeat clause) acts as a container for the rows.

 

And the second div tag (i.e. the second repeat tag, i.e. the select in the select)  acts as a container for the columns that will be positioned in the row-containers. 

 

This way the number of both rows and columns  are totally flexible. And, it's a totally clean solution that allows us to completely separate the layout from the content. 

 

Hope this helps.

 

Marcel Rietveld