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
Alo SenAlo Sen 

Is there a way to limit the number of rows returned by the value attribute in <apex:pageBlockTable>

There are 6 rows returned by the value attribute and I would like to show only 5 rows, since the 6th row is a column total which is required for reporting but does not need to be shown on the visual force page. How do I control this?
Best Answer chosen by Alo Sen
Amit Chaudhary 8Amit Chaudhary 8
Hi Als Sen,

Please try <apex:variable tag. This will resolve your issue.
 
<apex:page controller="sample">
    <apex:pageBlock >
    <apex:variable var="i" value="{!0}"/>
        <apex:pageBlockTable value="{!acnt}" var="acc">
            <apex:column >
                {!i}
                <apex:variable var="i" value="{!i+1}"/>
            </apex:column>
            <apex:column rendered="{! IF((i <= Size, true, false)}" value="{!acc.Rating}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Please create a vaiable "Size" in your controller. And use rendered in column so that last record will not visible in table.

Link:-
https://www.salesforce.com/docs/developer/pages/Content/pages_compref_variable.htm
http://www.infallibletechie.com/2012/11/how-to-increment-apexvariable.html
http://www.eltoro.it/ArticleViewer?id=a07A000000NPRiPIAX
http://www.codespokes.com/2013/01/how-to-use-apexvariable-in.html

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Hi Als Sen,

Please try <apex:variable tag. This will resolve your issue.
 
<apex:page controller="sample">
    <apex:pageBlock >
    <apex:variable var="i" value="{!0}"/>
        <apex:pageBlockTable value="{!acnt}" var="acc">
            <apex:column >
                {!i}
                <apex:variable var="i" value="{!i+1}"/>
            </apex:column>
            <apex:column rendered="{! IF((i <= Size, true, false)}" value="{!acc.Rating}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Please create a vaiable "Size" in your controller. And use rendered in column so that last record will not visible in table.

Link:-
https://www.salesforce.com/docs/developer/pages/Content/pages_compref_variable.htm
http://www.infallibletechie.com/2012/11/how-to-increment-apexvariable.html
http://www.eltoro.it/ArticleViewer?id=a07A000000NPRiPIAX
http://www.codespokes.com/2013/01/how-to-use-apexvariable-in.html

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
This was selected as the best answer
Alo SenAlo Sen
Thank you very much, this is so clear and helpful.