Search This Blog

Wednesday, October 23, 2019

Display elements of a list by skipping first few elements of it in visualforce page

We can display list by skipping specified number of elements using first attribute of <apex:repeat> tag.

Apex Code: DisplayElements
public class DisplayElements {
    public List<Integer> lstNumber {get;set;}
    public DisplayElements() {
        lstNumber = new List<Integer>();
        for(integer i=1; i<20; i++) {
            lstNumber.add(i);
        }
    }
}

Visualforce Page:

<apex:page controller="DisplayElements" id="thePage">
    <b>Elements after skipping first 5 elements:</b><br/>
    <apex:repeat value="{!lstNumber}" var="num" id="theRepeat" first="5">
        <apex:outputText value="{!num}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Output:

Display first 5 elements of a list in visualforce page - Salesforce Globe For You

Display first 5 elements of a list in visualforce page

We can display first specified number of elements using rows attribute of <apex:repeat> tag.

Apex Code: DisplayFirst5Element

public class DisplayFirst5Element {
    public List<Integer> lstNumber {get;set;}
    public DisplayFirst5Element() {
        lstNumber = new List<Integer>();
        for(integer i=1; i<20; i++) {
            lstNumber.add(i);
        }
    }
}

Visualforce Page: DisplayFirst5Element

<apex:page controller="DisplayFirst5Element" id="thePage">
    <b>First 5 Elements are:</b><br/>
    <apex:repeat value="{!lstNumber}" var="num" id="theRepeat" rows="5">
        <apex:outputText value="{!num}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Output: