Implement a search feature in the client

I want to implement a search feature to find windows. Our project grew to about ~150 different windows organized in navigation tabs and menus. It would be wholesome if users could search for a specific window and get a drop down list with links to the different windows that match the search criteria.

What would be the best way to go about this? I’m sure the information is already stored in the internal db… Is that accessible to devs?

Unfortunately, I’m not aware of an easy way to programmatically generate a list of all the window paths. It might be in some internal DB, like you said, but I’m not sure where. Maybe someone from Ignition can comment on this.

As for the implementation, that part is relatively easy. Here’s one method you could use:

So, first of all, you make a dataset tag with two string columns. In my example, it’s called “My Dataset Tag”, and the columns are “Window” and “Text”. You populate the dataset with the paths to your windows in “Window” and their respective plain-text names in “Text”. If your window paths are methodical, then maybe you can do most of this with a script; otherwise you do it manually.

On your display, you put a text field and a dropdown list. Here is the propertyChange script I wrote for the text field, to populate the dropdown list. Obviously, you’ll have to change the names of things to make it match your setup.

if event.propertyName == "text":
	resultHeaders = ["Window", "Text"]
	resultData = []
	myDataset = system.tag.read("My Dataset").value
	for row in range(myDataset.rowCount):
		myText = myDataset.getValueAt(row,"Text")
		if event.newValue in myText:
			myPath = myDataset.getValueAt(row,"Window")
			resultData.append([myPath, myText])
	results = system.dataset.toDataSet(resultHeaders, resultData)
	event.source.parent.getComponent('Dropdown').data = results

At that point, if it all works, you should be able to type into your text box and see the list update in your dropdown. Now, to go to the window, you can either put a propertyChange script on the dropdown so it navigates as soon as they select something, or put a button somewhere that navigates on click. Here is a sample script for the button idea:

target = event.source.parent.getComponent('Dropdown').selectedStringValue
system.nav.swapTo(target)

The dropdown list hides the results until you click to expand it. If you want to see the list of results updating as you type, you can use a table instead of a dropdown list, and use the selected row for your window selection to navigate. In the text box properties, under “Behavior”, make sure “Defer Updates” is not checked. I think it’s kinda cool to see this in action if your computer isn’t terribly slow. If it does run too slow, you can always check “Defer Updates”, and uncheck “Commit On Focus Loss”, and the list will only repopulate when the user presses “enter”…

I hope this helps!

3 Likes

The name of the function is a bit misleading, but system.gui.getWindowNames will return the path to all windows in a project as a tuple. This plus the info @zacslade provided should get you a solid start.

2 Likes