1

I understand that this needs to be done using the infamous wrapper class, but for some reason I am not able to get it to work. Any help would be great.

Goal: Display multiple List<String> as columns.

Something like this: enter image description here

I would like to use pageblockTable to accomplish this (or perhaps a pageblockTable within a pageblockTable).

I am storing each column data in a List<String> and it does NOT have a fixed number of entries. Each such List<String> needs to repeat as columns for as many years as specified by user input.

    public class Summary{
            public List<String> summary_list {get; set;}

            public Summary(List<String> s){
                summary_list = s;
            }
        }

        public List<Summary> summary_list_wrap {get; set;}
        public List<String> items_in_column {get; set;}

public void build_Table(){
     //populating the data here - which is working as per the screenshot below
}

The values of summary_block_wrap look like this when printed using the below code:

<apex:pageblockTable value="{!summary_list_wrap}" var="slw">
                        <apex:column value="{!slw}"/>
                    </apex:pageblockTable>

enter image description here

How do I tweak my visualforce page to match the desired layout?

EDIT: After implementing the answer suggested by Ashwani, the output looks like below. How can we format the table to remove the spacing between the columns and trim the column widths?

enter image description here

1 Answer 1

5

You should create a 2 dimensional array or we can say List of List which looks like List<List<String>> twoDimArray and try to iterate it like:

<apex:repeat value="{!twoDimArray}" var="dimension1">
  <apex:pageBlockDataTable value="{!dimension1}" var="dimension2">
    <apex:column value="{!dimension2}"/>
    <!-- etc -->
  </apex:pageBLockDataTable>
</apex:repeat>

Here you will have to arrange the collection properly. Possible iteration can be:

<apex:repeat value="{! summary_list_wrap}" var="dimension1">
  <apex:pageBlockDataTable value="{!dimension1. summary_list}" var="dimension2">
    <apex:column value="{!dimension2}"/>
    <!-- etc -->
  </apex:pageBLockDataTable>
</apex:repeat>

OP ADDED OUTPUT: enter image description here

I would like the output table style to look like that of pageblockTable. But is there a way to get rid of the spacing between the columns? And why is the last column squeezed as opposed to others? I would like to have a 'space trimmed' table instead of something with 100% width and wide spaces in between. How?

10
  • The number of entries in neither dimension 1 nor dimension 2 are static, so repeating apex:column a fixed number of times is not an option. Commented Feb 15, 2015 at 7:01
  • If you see there is <apex:repeat> which will handle no. of rows. It would be summary_list_wrap and apex:pageBlockDataTable> will iterate summary_list @Kal
    – Ashwani
    Commented Feb 15, 2015 at 7:11
  • I would like the output table style to look like that of pageblockTable. But is there a way to get rid of the spacing between the columns? And why is the last column squeezed as opposed to others? I would like to have a 'space trimmed' table instead of something with 100% width and wide spaces in between. How? Commented Feb 15, 2015 at 7:27
  • You can use css or style attribule on apex column to set the size @kal
    – Ashwani
    Commented Feb 15, 2015 at 7:33
  • I tried that but no luck. And how to get rid of the spacing in between the columns? That I think has nothing to do with the width of the column itself, right? Commented Feb 15, 2015 at 7:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .