Power Table's initialize method is never triggered/called

I place this code in initialize() and it never runs nor throws an error. When I place it into a button and it works fine.
Data property of the power table is bound to an SQL query that returns 3 columns. I want to add 4 columns to the existing 3 columns and initialize all values to 0. I tried to add them manually by editing data property. I added a column and give it name and type, but once I close the window and reopen, that column is gone!
I figured I should add columns through scripting when a window is opened.

def initialize(self):
	columnData = []
	for i in range(self.data.getRowCount()):
		columnData.append(0)
	
	colCount = self.data.getColumnCount()
	columnName = "col1"  
	ds2 = system.dataset.addColumn(self.data, colCount, columnData, columnName, int)
	self.data = ds2
	
	colCount = self.data.getColumnCount()
	columnName = "col2"
	ds2 = system.dataset.addColumn(self.data, colCount, columnData, columnName, int)
	self.data = ds2
	
	colCount = self.data.getColumnCount()
	columnName = "col3"
	ds2 = system.dataset.addColumn(self.data, colCount, columnData, columnName, int)
	self.data = ds2
	
	colCount = self.data.getColumnCount()
	columnName = "col4"
	ds2 = system.dataset.addColumn(self.data, colCount, columnData, columnName, int)
	self.data = ds2

In a button, self.data becomes event.source.parent.getComponent('Power Table').data of course
I’m wondering if I can’t use getColumnCount() and getRowCount() inside extention functions?!

Ignition Platform Version: 7.9.7
Java Version: 1.8.0_171

I copy - paste your code in a Power Table and it’s working for me.
I think your issue is due to the SQL query binding because if you have set the Pooling Mode to OFF, the query will run once when the enclosing window is opened and every time the query itself changes.
So I think the initialize event occurs before the query event. Result = your 4 columns are overwritten from the query event.

Yeah, don’t try to modify properties that are get their values from bindings – your changes will just get squashed. Attach your query binding to a custom dataset property, and use a value change event watching that property to compute and write to the original property.

Thank you! That makes sense.
I actually thought of another way that may not be the best way to do it, but it actually worked. I added the above code to mouseEntered on root container where the table is. The purpose of having those 4 additional columns is that I want to display (using system.dataset.updateRow()) calculated values depending on the values of the first 3 columns. If there is a smarter way to display these values, I’m open for suggestions :slight_smile: