4

I am creating PDF page (in html page not working too), I have pageBlockTable in it. I need to display row number in first column. I found solution to use apex:variable and increment it.

 <apex:variable value="{!0}" var="index"/>
    <apex:pageBlockTable value="{!salesOrderItems}" var="salesOrderItem" border="1px">
        <apex:variable var="index" value="{!index + 1}"/>
        <apex:column>
            <apex:facet name="header">
                <apex:outputLabel value="Number" />
            </apex:facet>
            <apex:outputLabel value="{!index}" />
        </apex:column>
        ...
     </apex:pageBlockTable>

But in every row I see 0. Increment is not working.

2 Answers 2

6

The dataTable and pageBlockTable elements do weird things for content outside of apex:column elements (usually by way of ignoring the content entirely). If you put the counter inside a column, it will work:

<apex:page controller="counter">
    <apex:variable value="{!0}" var="index" />
    <apex:pageBlock>
        <apex:pageBlockTable value="{!elements}" var="element">
            <apex:column>
                <apex:outputText>
                <apex:variable value="{!index + 1}" var="index" />
                {!index}
                </apex:outputText>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
2
  • Thanks, this works. Your solution to do it with css - salesforce.stackexchange.com/questions/111919/… works in html, but not in PDF Commented Apr 13, 2016 at 21:39
  • 2
    @VladyslavKushney Yeah, the CSS engine in PDF mode is a bit behind the times. I had thought there was a solution were you could increment a counter in a table, and there was actually another question recently about content appearing outside the table, which reminded me of that idiosyncrasy.
    – sfdcfox
    Commented Apr 13, 2016 at 21:41
4

According to this page, it is unsupported.

Though most of us have used it inside of an <apex:repeat> without problems, I suspect that the VF engine works differently in an <apex:PageBlockTable> and the counter does not get incremented.

3

You must log in to answer this question.

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