Initialize on swap

I’ve been working on a project that requires I change the columnAttributesData dataset on initilization of the window. Up til now I’ve been swapping my window from a docked window which passes parameters onto the mainwindow to dynamically fill the powertable on that window, however since swapping doesn’t initializeI’ve run into a problem.

is it possible to make my initialize function run on swap or maybe put my script somewhere else to make it run correctly? I’d like to avoid tonnes of instances of my window running at once.

Thanks for any help!

Consider including a dataset property on the target window’s root container, and bind that to the chart’s c-a-d. Then your window swapping calls would include the necessary initial dataset in the parameters to swapWindow(). This approach also allows each target to have a different c-a-d. And can be extended to pre-populate pens and tagPens on the chart, too.

Good Idea! I just tried it out, but even though by all means it should work and update the binding, whenever I change the custom property the changes don’t get reflected on screen.

One point of clarification, I’m using this to asign header labels to a powertable that gets filled dynamically. The labels get pulled from a database and then I make a dataset to fill the c-a-d.
I’m fairly new to Ignition, so I don’t know if charts relate to powertables relevantly in my situation.

Sorry, mixed those two up. But the concept applies. However, you may need to ensure the c-a-d is populated before the table data. I don’t recall if c-a-d actually fires a propertyChange event.

I make the c-a-d on my navigation button using this code:

param2 = ""
param1 = event.source.parent.getComponent('Dropdown Table Selection').selectedStringValue



if event.source.parent.getComponent('Dropdown Table Selection').selectedValue != -1:
	columnPyData = system.db.runPrepQuery("Select columnName FROM MasterData WHERE tableName = '"+param1+"';")
	for row in columnPyData:
		for value in row:
			value = unicode(value, "utf-8")
			param2 = param2 + value + ", "

		
	param2 = param2[:-2]
	tableName = param1
	headers = ["name", "editable", "label"]
	columns = param2.split(", ")
	data = []
	for colName in columns:
		columnHasDropdown = system.db.runScalarPrepQuery("SELECT hasDropdown FROM MasterData WHERE tableName = '"+tableName+"' AND columnName = '"+colName+"'")
		colName = str(colName)
		if columnHasDropdown:
			alias = str(system.db.runScalarPrepQuery("SELECT alias FROM MasterData WHERE tableName = '"+tableName+"' AND columnName = '"+colName+"'"))
			data.append([colName, 1, alias])
		else:
			data.append([colName,1, ""])
			
	param3 = system.dataset.toDataSet(headers, data)
	for row in range(param3.getRowCount()):
	    for col in range(param3.getColumnCount()):
	        print param3.getValueAt(row, col)
	
	
	system.nav.swapTo('DynaCRUD/MainWindows/CRUD Window', {'TableName' : param1, 'Columns' : param2, 'ColAtrDat' : param3})

It’s a bit messy, but it should work.

I then have the c-a-d bound to the custom property like you suggested, this does cause a propertychange event to fire as I messed around with it, but it got stuck in a loop and made the program very unresponsive to input.

if you’re wondering how I populate the powertable this is the binding:

SELECT {Root Container.Columns}
FROM {Root Container.TableName}
WHERE {Root Container.Text Field.search};

the search property is filled with “1=1” by default.

Any suggestions as to what I could try?

I usually found that to be caused by a propertyChange event routine somewhere that isn't checking the event.propertyName before doing any work.

oops, guess I forgot, but still it isn’t giving me the results I’d hoped for.

I think your suggestion of populating the c-a-d before the table was correct, but since I’m always using the same instance of the window, how would I go about making sure it doesn’t break when I swap?

It might also be worth trying to figure out if I can use multiple instances but just close the old one. I didn’t see a nav function for that however.