Hey! Are you staying home? We are too. Still, we prepared a new product release for you!🚀

We hope it comes in handy for your business especially these days. Stay safe & pivot on!

How to expand a two levels hierarchy


I have a structure with multiple hierarchy and I want to set default expand for 2 levels of hierarchy, how can I do this? For example my hierarchy might start by Year> Month> Day and I may want to expand by default Year > current Month. I’ve read the documentation about expand objects and actually I’m able to expand only one hierarchy following the documentation example.


1 answer

WebDataRocks Team WebDataRocks November 1, 2019

Hello, Will,
Thank you for your question.
Our team kindly suggest you follow the steps below:

Choose the fields you want to be shown and expanded.

Include them into the Slice object as a rows array element, here you can find how to do that: https://www.webdatarocks.com/doc/slice-object/.

Add an expands object into the slice with suitable properties. More about expands object you can find by following the link above. Please note, that using that approach allows you to set default expansion only for specific members of the field which you indicate manually. Find out an example of using expands object by the link https://codepen.io/webdatarocks/pen/.

In your case, this approach will manage to expand only currentMonth member of the months field.

To expand each member of the field, use expandData method with required parameters, in your case, these parameters will be presented by fields names, for example:


Add several expandData methods if you want to expand for more than one level of the hierarchy.

Please, find out an example with two levels hierarchy by following the link below: https://codepen.io/webdatarocks/pen/qBBVzGK.

Also, please note that you can simply adjust the table using the UI and save it as a JSON. The obtained configuration will allow you to reuse such a layout in the future. You can find more information here: https://www.webdatarocks.com/doc/saving-and-opening-reports/.
WebDataRocks Team

Please login or Register to Submit Answer