Hide/Show Sections on a Document

I originally had this idea for a method to hide and show elements on the fly on a Document last year, but it didn’t quite work out.  The two major problems that prevented me from using it in production were that I couldn’t find a way to have the object start out hidden, and once hidden it just left a gap or space instead of resizing the content around it.  I’m happy to report that after some slight modifications to the method, I’ve solved both problems and implemented it into a recent dashboard I built.  This solution doesn’t require any customizations and will work in 9.0+.

The steps are similar to last time, but I’m going to put them in detail here.  I’m doing a separate post for this since this is a better way to do it, but since that post is old and circulated, I don’t want to delete it and break links.

Step 1 – Layout Your Document
The basic idea last time was to hide/show objects, and I did a proof of concept with a grid.  The first improvement is instead to do this with a section.  For one, it provides more flexibility for implementation because you can put any number of components in the section without adding complexity to this hack.

In this example, I’ve created 3 sections.  The middle section I’ve filled in gray so that it’s very obvious where it is, and added some controls like a text box, a Panel Stack and a Grid.  Now what we’ll do is add some code to dynamically hide the gray section.

Step 2 – Get the Section Handle
Here you need to use either Chrome or Firebug to find the ID of the Section.  The ID is set at design time and won’t change, so after you’ve laid out your document, you just have to find it one time and you’re good.

In Chrome, run the document like normal and right click anywhere inside the middle (gray) section.  Choose Inspect Element from the menu and show the HTML code for the page and highlight the code for this section.  The value we’re interested in for this example is K8, which is the ID.  You can see it in the code or you can see it in the yellow tooltip that pops up at the bottom of the section.

Step 3 – Add an HTML Container
Go back to design mode and add an HTML Container object (Insert -> HTML Container) and add the following code:

<a onclick="javascript:if(getElementById('K8').style.height=='300px') {getElementById('K8').style.height='0px'} else {getElementById('K8').style.height='300px'};">toggle</a>

The last time I tried this, the code I used was trying to set the visibility property of the object to make it hidden.  Unfortunately, this just left a blank space when we hid it, which wasn’t very useful.  This time however, we will modify the height of the section.  Since a section by nature can expand and collapse, this will automatically handle the repositioning of surrounding content.

What this code does is create a link called toggle and when you click on it, it will change the height of the target section between either 0 or 300 (pick whatever size works for you).  Don’t forget to replace the K8 in the above code with whatever your Section ID is.

In order to make the section “hidden” by default, right click on the section in design mode and set it’s height to 0.

Now when the document runs for the first time, the section will not be visible since it’s height is 0.  However, the content in that section is still there and will react to things like selectors.  When we click on the toggle link, it will increase the height of the section which will make it “visible” and reposition any content around it.

Tip: There appears to be a bug when embedding Javascript into an HTML Container.  The first time you run the document after modifying it, it doesn’t work.  Go back into Edit mode then back into Interactive mode, and then it does work.  So if you’re trying out this code and it doesn’t work the first time, try that first.

Here it is in action!

You may also like...

25 Responses

  1. swi3zy says:

    That is a very useful feature :-). Thanks for sharing!

  2. Hi Bryan. Is there any way that you know of to get this working in Express Mode? I have to use Express Mode because of information windows and transaction services but looking at the source code of the Express Mode page it doesn’t use div HTML elements as in the Interactive Mode. I also noticed using conditional formatting to hide objects doesn’t work in Express mode and does in Interactive mode (tested on 9.2 and 9.3). Thanks.

    • Bryan says:

      It looks like it still works the same way, but they use a different ID in the div tag. For example, on a working dashboard in interactive mode, my section had an ID of ‘K660’, but in Express Mode, the same section’s ID was ‘K660x1lK3’. I added the extra string at the end and the expand/collapse worked again. Good thing to know, the method for finding the IDs in the divs is the same as mentioned in the original post. Thanks for the catch.

  3. neny_ri says:

    Hi Bryan,

    I have a problem with resizing text box in the detail section on my document. Everything looks fine on the web, but on ipad the text box doesn’t grow dynamically. i had to put comments in detail section, because it’s a metric.
    Let me describe my document: I have a detail section for “comments”. I.e. if a comment has 1 or 2 rows it displays perfectly. but, if I have another comment under that one, and this new comment is longer ipad will display that long comment only partialy. do you have any advice?

    • Bryan says:

      Make sure that the section layout is set to “Height can Grow”. Other than that, it might just be a limitation with the Mobile app. I haven’t really done any MicroStrategy Mobile development, so I’m not sure where such issues are.

  4. meszikat says:

    hi Bryan,

    Any way to make this work in Flash?

    Thanks,
    Kati

  5. JBL says:

    So this wouldn’t work in iPad/Phone apps?

  6. Rob Lee says:

    Hey Bryan,

    I was excited to see this solution, but looking in the comments, I see it’s not functional for web. Do you have a solution to a similar problem in web? Is there any way to expand/collapse a section in web with a toggle button?

  7. Kelly Noskov says:

    Hi Brian. I got this to work (thank you!) but it insists on opening the section with it un-hidden even though I’ve set the height to zero. Any idea why that might be?

  8. Hi Bryan, I am running Flash video in my dashboard using HTML container. It is running fine. But while loading Dashboard, I am getting “Can not assign [Number]” Popup message in ClientSideDescriptor.js. When I click OK, Remaining things work fine. Can you please help ?

  9. This is list of Error, I am getting below error while executing Dashboard in IE.

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.1.4322; InfoPath.3)
    Timestamp: Fri, 26 Apr 2013 07:40:24 UTC

    Message: Expected ‘;’
    Line: 1884
    Char: 44
    Code: 0
    URI: /MicroStrategy/javascript/docCommands.js

    Message: Expected ‘;’
    Line: 582
    Char: 64
    Code: 0
    URI: /MicroStrategy/javascript/updateManager.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 528
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/mstrRWUnitBone.js

    Message: Cannot assign to ‘[number]’
    Line: 528
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/mstrRWUnitBone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: ‘mstrUpdateManager’ is undefined
    Line: 1
    Char: 1
    Code: 0
    URI: /MicroStrategy/javascript/updateManagerEventsRW.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 553
    Char: 1
    Code: 0
    URI: /MicroStrategy/javascript/mstrGridStatic.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Cannot assign to ‘[number]’
    Line: 352
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/bone.js

    Message: Expected ‘;’
    Line: 1218
    Char: 16
    Code: 0
    URI: /MicroStrategy/javascript/TabManager.js

    Message: Cannot assign to ‘[number]’
    Line: 528
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/mstrStaticDocViewer.js

    Message: Cannot assign to ‘[number]’
    Line: 970
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/mstrStaticDoc.js

    Message: Cannot assign to ‘[number]’
    Line: 553
    Char: 1
    Code: 0
    URI: /MicroStrategy/javascript/mstrGridStatic.js

    Message: Cannot assign to ‘[number]’
    Line: 15
    Char: 5
    Code: 0
    URI: /MicroStrategy/javascript/clientSideDescriptor.js

  10. This Errors are not preventing me to execute dashboard but only shows ugly pop up message firs time while executing dashboard.

  11. Hi Bryan,

    I am able to create Conditional formatting for each Sub Section through SDK. I am also able to select Checkbox called “Hide Section”. But Sections are still visible when I choose different Group By.
    For Example: I have 3 sub-sections like Title, Grid and Map and also I have added attribute which contains information of these sections in Group By. On select of Title from Group By, I want to hide Table and Map Sub-section.

    Thanks,
    Shyam Agrawal.

  12. prashanth says:

    Hi Bryan ,

    I have an requirement to have a prompt saying whether to display the details section or not .Would you please help me out in this .how to assign a prompt for hiding a particular section??

Leave a Reply

Your email address will not be published. Required fields are marked *