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