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
yogesh.rankawatyogesh.rankawat 

How to collapse & expand salesforce Collapsible Sidebar ?

Hello

How to collapse & expand  salesforce Collapsible Sidebar in visual foce using coding ?

Thanks
Yogesh



hisrinuhisrinu
Hi,

Specify like this in page.
<apex:page sidebar="false">




yogesh.rankawatyogesh.rankawat
Thanks for your quick reply....

But I want to collapse & expand the sidebar.... means I want a sidebar with collapse mode
Ron HessRon Hess
you must enable collapse sidebar in the setup area, under user interface

i don't think you can cause it to expand / collapse from visualforce without resorting to trickery


yogesh.rankawatyogesh.rankawat
I found the code.........

we can collapse & expand the sidebar using .....

<script  type="text/javascript">
  // ---- collapse sidebar --------
  if (document.getElementById('sidebarDiv')){
    Sidebar.prototype.theSidebar = new Sidebar(document.getElementById('sidebarDiv'), true, false);
  }
</script>

dchasmandchasman
NOTE: reverse engineering of our internal javascript is not supported by salesforce.com and we reserve the right (and are likely to) to change the javascript that you have created a dependency on which will result in your code failing at some undefined point in the future.
SForceBeWithYouSForceBeWithYou
Also, note that if you are in a home page component (narrow or wide), that you will more than likely be inside of an iframe, hence you'll want to search/use window.parent instead of just document.  I used the presence of the CSS class for when the sidebar is collapsed instead of the text of the title (which varies with language selected):
var handlebarContainers = window.parent.getElementsByClassName('handlebarContainer');
if(handlebarContainers.length > 0) {
  var sidebarCell = handlebarContainers[0].parentElement;
  var sidebarClasses = sidebarCell.classList;
  if(sidebarClasses != null && sidebarClasses.length > 0 && sidebarClasses.contains("sidebarCollapsed")) {
    handlebarContainers[0].click();
  }
}

I also used setTimeout() since I put this on the document "DOMContentLoaded" event of the home page component.  Trying to put the event listener on window.parent's DOMContentLoaded wasn't working.