# Power Table's initialize method is never triggered/called

**URL:** <https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 15, 2018, 4:55pm UTC](https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269 "2018-08-15T16:55:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.aziz](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mark.aziz](https://forum.inductiveautomation.com/u/mark.aziz)\
**Post date:** [August 15, 2018, 4:55pm UTC](https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269/1 "2018-08-15T16:55:33Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [August 16, 2018, 6:56am UTC](https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269/2 "2018-08-16T06:56:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 16, 2018, 10:28am UTC](https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269/3 "2018-08-16T10:28:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mark.aziz](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mark.aziz](https://forum.inductiveautomation.com/u/mark.aziz)\
**Post date:** [August 16, 2018, 12:49pm UTC](https://forum.inductiveautomation.com/t/power-tables-initialize-method-is-never-triggered-called/19269/4 "2018-08-16T12:49:43Z")

</div>

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 🙂
