How to auto expand Metadata Navigation in SharePoint

Hello everyone, in this post will discuss how to auto expand Metadata Navigation in SharePoint.

Metadata navigation can be very useful, it helps the user to create terms or tags which make life easy for user to search for any item.

Usually, out of the box metadata navigation doesn’t get expanded and it has to be expanded manually, which is kind of confusing for the user who is not familiar with SharePoint. In this article, I will discuss with small JavaScript code how can we enable it automatically once the user lands on the page.

Step 1: Create an app type list name it anything you want, I am giving list name: Metadata Navigation.

Step 2: Create metadata column call it Project type, if you don’t know how to create a column in SharePoint click here.


Step 3: Make sure you create some terms to serve the purpose if nothing is there under term sets (Project Type) , we won’t see anything after expanding it.


Step 4: Go to list setting, under general setting look for “Metadata navigation setting”, if you can’t find it.

Navigate to site setting under site actions, click on Manage site features and activate “Metadata Navigation and Filtering”


Now go back to the list setting and now you will see “Metadata navigation setting”, click on it and configure Navigation Hierarchies.

Select Project Type which we created and remove Folders which is by default gets added to selected Hierarchy fields.

Step 5: Navigate to list  “Metadata Navigation” list


You will notice that terms are not expanded, it requires manual work.

Steps to auto expand metadata Navigation

Step 1: Press F12 from the browser and hover over your mouse on the sub level (Project Type) small triangle shape, which comes under the Metadata Navigation list


Step 2: Add content editor web part to the list page and link it to the below code

Note: Look for JavaScript:TreeView_PopulateNode and copy the whole string

Create function expand()

_spBodyOnLoadFunctionNames array allows event handler to execute each function, which is used in thi array.

<script type="text/javascript">
function Expand()
{ try { TreeView_PopulateNode(ctl00_PlaceHolderLeftNavBar_ctl04_WebTreeView_Data,1,document.getElementById('ctl00_PlaceHolderLeftNavBar_ctl04_WebTreeViewn1'),document.getElementById('ctl00_PlaceHolderLeftNavBar_ctl04_WebTreeViewt1'),document.getElementById('ctl00_PlaceHolderLeftNavBar_ctl04_WebTreeViewt1i'),' ','Project Type','Metadata Navigation\\Project Type','t','30:FieldNameNode:bec55f5d-019b-43af-bcd4-990e2a6bfb8c:4b9b8b11-ed3b-41c4-ae38-a2ae217de5e1:2e23af5c-f1e7-4692-966c-bee1a079eedd:30|ListNode|bec55f5d-019b-43af-bcd4-990e2a6bfb8c|4b9b8b11-ed3b-41c4-ae38-a2ae217de5e1|95af593a-620c-4751-b5b4-470c7bd0445f','tt');
catch (err) { }


Finally, after putting the above script, refresh the page and metadata navigation is auto-expanded


I hope this article will help you guys, if you have any questions orsuggestion, let me know. 

Thank you for visiting my blog. 🙂

Leave a Reply

Be the First to Comment!

Notify of

Enjoy this blog? Please spread the word :)