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
TejTej 

how to display the long list in different lines in a page

I have a requirement where there is a list of strings which is quite big, around few thousands. but need to be displayed in different lines and could be able to export/ take print etc...
please check the below image for reference.

please help.

 User-added image
Best Answer chosen by Tej
Elie.RodrigueElie.Rodrigue
The way i would approch this would be to create a list of list that represent the table : 
List<List<string>> toDisplay = new List<List<string>>();

First list behing rows, second one behing columns.
You then populate that double list based on your initial list : 
List<string> initialList = new List<string>()
//Add x thousand entries to the list here


integer nbOfColumns = 8;
List<List<string>> toDisplay = new List<List<string>>();
List<string> currentList = new List<string>();
for(string str : initialList)
{
if(currentList.size()>=nbOfColumns)
{
  toDisplay.add(currentList);
  currentList = new List<string>();
}
currentList.add(str);
}
if(currentList.size()>0)
{
toDisplay.add(currentList);
}


Once the list of list is exposed in visualforce : 

<table>
<apex:repeat value="{!ListOfList}" var="List">
<tr>
     <apex:repeat value="{!List}" var="entry">
              <td>{!entry}</td>
     </apex:repeat>

</tr>
</apex:repeat>
</table>




You could also achive the same with standard vf component using the same logic, but it was faster to write using table html tags :)

I hope it solve your issue! 

All Answers

Elie.RodrigueElie.Rodrigue
Can you provide us with a sample file containing the raw string?

Basically you should be able to string.split your input and output in the format you want in a visualforce page.
How does the code aquire the string? Is it a document in salesforce? An attachment? Result from an http request?

Regards,
TejTej
actually these are the records in salesforce but we only need one field which are these numbers. and display in multiple columns as shown and it may go upto few pages becuase there might be few thousand records.
we are doing the query to fetch the eligible records.and adding the field with number to list<String>, so everything ready to go but the display.
Elie.RodrigueElie.Rodrigue
The way i would approch this would be to create a list of list that represent the table : 
List<List<string>> toDisplay = new List<List<string>>();

First list behing rows, second one behing columns.
You then populate that double list based on your initial list : 
List<string> initialList = new List<string>()
//Add x thousand entries to the list here


integer nbOfColumns = 8;
List<List<string>> toDisplay = new List<List<string>>();
List<string> currentList = new List<string>();
for(string str : initialList)
{
if(currentList.size()>=nbOfColumns)
{
  toDisplay.add(currentList);
  currentList = new List<string>();
}
currentList.add(str);
}
if(currentList.size()>0)
{
toDisplay.add(currentList);
}


Once the list of list is exposed in visualforce : 

<table>
<apex:repeat value="{!ListOfList}" var="List">
<tr>
     <apex:repeat value="{!List}" var="entry">
              <td>{!entry}</td>
     </apex:repeat>

</tr>
</apex:repeat>
</table>




You could also achive the same with standard vf component using the same logic, but it was faster to write using table html tags :)

I hope it solve your issue! 
This was selected as the best answer
TejTej
That worked like a charm.... Thank you So much .. 
Elie.RodrigueElie.Rodrigue
you are welcome!