# Dynamic Navigation Tree Ideas

**URL:** <https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767>\
**Category:** Ignition\
**Created:** [March 3, 2015, 7:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767 "2015-03-03T19:23:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iampatrick](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@iampatrick](https://forum.inductiveautomation.com/u/iampatrick)\
**Post date:** [March 3, 2015, 7:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/1 "2015-03-03T19:23:15Z")

</div>

I need to be able to display different items in the a navigation tree, based on the roles assigned to the logged in user. Does anyone have an idea what the best way to achieve this would be? It seams that someone would have done this before.

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [March 3, 2015, 10:30pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/2 "2015-03-03T22:30:36Z")

</div>

In the Cloud Templates Browser, under Navigation they have a Auto Tree Nav template. Is this something like what you are looking for?

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![iampatrick](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@iampatrick](https://forum.inductiveautomation.com/u/iampatrick)\
**Post date:** [March 4, 2015, 3:10pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/3 "2015-03-04T15:10:25Z")

</div>

Chris, thanks for the suggestion. I may be able to use the Auto Tree Nav template to help me get started.

The trick is going to be how to omit certain window paths, based on the current user’s roles.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [March 4, 2015, 3:42pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/4 "2015-03-04T15:42:30Z")

</div>

[quote=“iampatrick”]Chris, thanks for the suggestion. I may be able to use the Auto Tree Nav template to help me get started.

The trick is going to be how to omit certain window paths, based on the current user’s roles.[/quote]

store it in the database. have an id for each window path, and then have a separate table in the database that uses that pathid and maps it to a role/roles. then when the user logs in check their role and run a query and or scripting that builds the dataset used by the tree component.

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [March 4, 2015, 3:45pm UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/5 "2015-03-04T15:45:53Z")

</div>

you could add additional custom tables to the template…

Like AdminList, ManagerList, etc…

Then just modify the code a little to include those windows in the skip list…

Like so:

```auto
# dynamically create the set of windows.

if event.propertyName == "componentRunning":
	# get what we already know
	header = ["windowPath","path","text","icon","background","foreground","tooltip","border","selectedText","selectedIcon","selectedBackground","selectedForeground","selectedTooltip","selectedBorder"] 
	icon = "Builtin/icons/16/document.png"
	background = "color(255,255,255,255)"
	foreground = "color(0,0,0,255)"
	tooltip = ""
	border = ""
	selectedIcon = "Builtin/icons/16/document.png"
	selectedBackground = "color(250,214,138,255)"
	selectedForeground = "color(0,0,0,255)"
	selectedTooltip = ""
	selectedBorder = ""
	data = []
	
	
	# get the window paths for all windows in the project
	projectWindows = system.gui.getWindowNames()
	# set up a list of windows to skip
	skipList = []
	skipDataset = system.dataset.toPyDataSet(event.source.parent.skipList)
	for row in skipDataset:
		skipList.append(row[0])
		
	if "Administrator" not in system.security.getRoles():
		adminDataset = system.dataset.toPyDataSet(event.source.parent.adminList)
		for row in adminDataset:
			skipList.append(row[0])
			
	if "Manager" not in system.security.getRoles():
		managerDataset = system.dataset.toPyDataSet(event.source.parent.managerList)
		for row in managerDataset:
			skipList.append(row[0])
	 
	# loop through and add the windows
	for projectWindow in projectWindows:
	
		# seperate the path from the window name
		windowPath = projectWindow
		# split the path on the last /
		index = projectWindow.rfind("/")
		if index == -1:
			path = ""
			text = projectWindow
		else:
			path = projectWindow[:index]
			text = projectWindow[index+1:]
		
		# skip the windows in the skip list
		# skip the folder if there's a / at the end
		if not (projectWindow in skipList or path+"/" in skipList):
			# append to the final data set
			data.append([windowPath,path,text,icon,background,foreground,tooltip,border,text,selectedIcon,selectedBackground,selectedForeground,selectedTooltip,selectedBorder])
	
	# push data to the tree view component
	event.source.data = system.dataset.toDataSet(header, data)
```

Hope that helps.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![iampatrick](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@iampatrick](https://forum.inductiveautomation.com/u/iampatrick)\
**Post date:** [April 23, 2015, 1:50am UTC](https://forum.inductiveautomation.com/t/dynamic-navigation-tree-ideas/9767/6 "2015-04-23T01:50:20Z")

</div>

I was able to get this to work for me.

Thanks!
