I’m not sure why you’re not getting any replies to this, but I am doing this successfully in Ignition 7.9.9.
I have a table whose columns are very numerous and change dynamically based on the division of the company whose data you are viewing. I created a button so that each user can save their column order and widths for each location in a database. Here is the actionPerformed script for the button.
import sys
#Retrive user id from username
un = system.tag.read("[System]Client/User/Username")
uname = un.value
vallst = [uname]
qry = "SELECT ID from [dbo].[tblPeoplelist] WHERE ADUsername = ?"
rtn = system.db.runScalarPrepQuery(qry,vallst)
#print("Username was: %s ID was %s and check for INT is:%s" % (vallst[0],rtn,isinstance(rtn, (int, long))))
#sys.exit()
if not isinstance(rtn, (int, long)):
# Couldn't find a used id from the username
system.gui.messageBox("Sorry, I don't know who you are.\n\nYou must be logged in with your Interfor username and\n" \
"that user name must be entered into the Interfor personnel list\nwith the Personnel Manager\n\n" \
"I see your username as: \n\n%s" % (uname))
sys.exit()
empid = rtn
loc = event.source.parent.getComponent('ddLocation').selectedValue
if loc < 1:
# Don't have a location selected in the drop dowm
system.gui.messageBox("You need to pick a location in the Location drop down box")
sys.exit()
# Check to see if we need to update an existing saved layout or create a new one
qry = "SELECT COUNT(ID) from [dbo].[sftyTrnLayouts] WHERE Emp = ? AND Location =?"
vallst = [empid,loc]
rtn = system.db.runScalarPrepQuery(qry,vallst)
tbl = event.source.parent.getComponent('ptTrainingTable')
layout = tbl.defaultColumnView
vallst = [layout,empid,loc]
if rtn:
# There was already a layout saved for this user and this location, so just update it
qry = "UPDATE [dbo].[sftyTrnLayouts] SET Layout = ? WHERE Emp = ? AND Location =?"
value = system.db.runPrepUpdate(qry, vallst, "MillDB")
else:
# There wasn't already a layout saved for this user and this location, so we need to insert a new record
qry = "INSERT INTO [dbo].[sftyTrnLayouts]([Layout],[Emp],[Location]) VALUES (?,?,?)"
value = system.db.runPrepUpdate(qry, vallst, "MillDB")
And then I have a button that (whose script isn’t well documented) that retrieves the saved layout and applies it to the table.
import sys
un = system.tag.read("[System]Client/User/Username")
uname = un.value
vallst = [uname]
qry = "SELECT ID from [dbo].[tblPeoplelist] WHERE ADUsername = ?"
rtn = system.db.runScalarPrepQuery(qry,vallst)
#print("Username was: %s ID was %s and check for INT is:%s" % (vallst[0],rtn,isinstance(rtn, (int, long))))
#sys.exit()
if not isinstance(rtn, (int, long)):
system.gui.messageBox("Sorry, I don't know who you are.\n\nYou must be logged in with your Interfor username and\n" \
"that user name must be entered into the Interfor personnel list\nwith the Personnel Manager\n\n" \
"I see your username as: \n\n%s" % (uname))
sys.exit()
empid = rtn
loc = event.source.parent.getComponent('ddLocation').selectedValue
if loc < 1:
system.gui.messageBox("You need to pick a location in the Location drop down box")
sys.exit()
qry = "SELECT COUNT(ID) from [dbo].[sftyTrnLayouts] WHERE Emp = ? AND Location =?"
vallst = [empid,loc]
#print("Returned value was:%s" % (rtn))
#sys.exit()
if rtn:
qry = "SELECT [Layout] FROM [Mill].[dbo].[sftyTrnLayouts] Where Emp = ? AND Location = ?"
layout = system.db.runScalarPrepQuery(qry,vallst)
tbl = event.source.parent.getComponent('ptTrainingTable')
tbl.defaultColumnView = layout
else:
system.gui.messageBox("Sorry, I don't have a layout saved for you for this location")
Note: I have not been able to do anything with the columnAttributesData property. I can change that with a script, but the table will not reflect the properties. So this will only change column order and column width.