1

I have an <apex:datatable> like this :

<apex:dataTable value="{!accList}" var="account">
    <apex:column>
        <apex:facet name="header">Account ID</apex:facet>
        <apex:outputText value="{!account.Id}"/>
    </apex:column>
    ...
</apex:datatable>

But the datatable displays all my Accounts. Is there a way to limit the number of rows displayed and have a scrollbar ? I want all my Accounts be displayed but only show 10 for example at a time.

And do you know if there is an attribute to keep headers always visible after I scroll down ?

  • How are you intending to display this page? Is it a related list on another record? Passing an id will limit the results. You can also utilize an extension to the controller, and use a query to limit what is put on the page. Right now you're just saying "give me all the accounts" without any criteria. As far as the scrollbars, again, depending on the intent, you can add scrollbars to an element added to a standard layout. – HomerJ Jan 16 '15 at 15:49
  • No, it's a simple list showing all my accounts. And I don't want to put a limit in my query. I want all my accounts displayed but in a datatable showing only 10 of them at a time. And I want a scrollbar to access to all of them. – SF_user Jan 16 '15 at 15:52
  • I see, so you want a table that is '10 rows high'. I would be concerned about a table return without SOME sort of limit tho. You'll be sorry if you don't. – HomerJ Jan 16 '15 at 16:06
2

Try putting a div around your datatable with an overflow style and max height. Other overflow options are available.

<apex:outputPanel layout="block" style="max-height:400px; overflow:scroll" id="main">
<apex:dataTable value="{!accList}" var="account">
    <apex:column>
        <apex:facet name="header">Account ID</apex:facet>
        <apex:outputText value="{!account.Id}"/>
    </apex:column>
    ...
</apex:datatable>
<apex:outputPanel>

I have a pageblock inside an output panel and it works a treat to limit the real estate consumed but allow the user to view all fields by scrolling.

  • It works well thank you ! And do you know if it's possible to fix the headers row ? I want the header row always be displayed even when user scrolls down. – SF_user Jan 19 '15 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.