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
Jon KeenerJon Keener 

Setting how a Collapsible PageBlockSection is rendered

Is there any way to force a Collapsible PageBlockSection to start in a collapsed mode, when the page is rendered?  I know with standard page layouts, this isn't possible, but Salesforce remembers what a user chooses and uses that in the future to determine the collapsible state when rendering a page.  So far, I have not seen this same behavior with Visualforce pages.  It would be nice to have a parameter on the PageBlockSection that controls the initial behavior of a collapsible PageBlockSection when it it first rendered.
 
Jon Keener


Message Edited by Jon Keener on 02-14-2008 01:06 PM
parkerAPTparkerAPT
While certainly not the most robust solution because it is not officially supported. You can call the javascript that toggles the section in order to hide a section by default:

Code:
<apex:pageBlockSection title="{!sectionTitle}" id="theSection" columns="1">

<!-- Section contents here -->
</apex:pageBlockSection>

<script>
function customToggleSection(el){
if(typeof twistSection === 'function'){
var theTwist = document.getElementById(el);
if(theTwist){
// twistSection expects you to click on the IMG link, this targets that img
HTMLelement
twistSection(theTwist.childNodes[0].childNodes[0]);
}
}
}

customToggleSection('{!$Component.theSection}');
</script>



rajarakrajarak

Parker,

 

I am trying to achieve same functionality.

In the above sample code, we are passing the reference of the VF component to twistSection.

But, where exactly are we setting the default collapsed setting for pageblocksection?

 

In Salesforce Jscript library, they have twistSection method that does the implementation

for collapse and expand function of a section.

 

Is it possible to change the settings in their library?

 

Please post a sample code.

 

Thanks

KK 

 

 

cpetersoncpeterson

So I know it's about a year late, but I needed to do this for my own project, and figured I'd share some sample code.

 

1. uploaded a static resource, pageBlockSupplement.js, containing: 

 

function PageBlockSectionCollapse(el){ if(typeof twistSection === 'function'){ var theTwist = document.getElementById(el); if(theTwist){ // twistSection expects you to click on the IMG link, this targets that img twistSection(theTwist.childNodes[0].childNodes[0]); } }}

 2. made a new VF page containing:

 

<apex:page tabstyle="CustomObject__c" standardController="CustomObject__c"><apex:includescript value="{!$Resource.pageBlockSupplement.js}" /> <apex:pageBlock > <apex:pageblockSection columns="1" showHeader="true" title="Add CI Relationships" id="CIRel"> <script>PageBlockSectionCollapse('{!$Component.CIRel}');</script> <c:myComponent target="{!$CurrentPage.parameters.id}" showFilters="true"/> </apex:pageblockSection> </apex:pageBlock></apex:page>

 

You can call the includeScript anywhere, but the call to PageBlockSectionCollapse needs to be within the pageBlock. 

 

 

 

 

Paulo CastroPaulo Castro

It would be nice to have this feature natively.

 

If you want too, please help to promote this ideia:

 

http://ideas.salesforce.com/article/show/10098227/Add_Collapsedtrue_option_to_ltapexpageblocksection