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
ngabraningabrani 

Displaying collections

Couple of questions on displaying collections in a tabular format

1. Lets say an Apex controller is returning an List of 50 elements. I want to display five columns of ten elements each - first column with first ten elements, second column with next ten and so on... What is the best way to implement this

 

2. Lets say an Apex controller is returning a Map. Key is a String and value is a list of String. In VisualForce, For all the keys, I need to display Key as the column header, and I need to display strings in the list corresponding to the key as elements in the column. What is the best way to implement this.

 

Many Thanks.

bob_buzzardbob_buzzard

1.  I'd suggest that you implement a custom class that that contains five elements.  Then convert your list of 50 elements to a list of your custom class, one instance of the custom class per row.  Then you can iterate the list and output each element as a column.  

 

2. Similar to the above.  Have a custom class that contains as many elements as you have entries in the map.  Create one instance of this for the headers and populate it with the keys from the map. Then create a list of these containing the entries for each row.  Then use repeat tags and vanilla HTML tables to iterate the headers and rows and output these as table headers, rows and cells as required.

 

I've used both of these techniques in the past without problems.