Perspective Table Edit certain cells and write into DB

Hello all,

I want to know a 2 things about Ignition perspective table.

  1. How do I make certain cell ‘editable’ automatically when the table.props.data changes
  2. I have created a script to write updated values into DB, but not sure if its a safe and standard way.

#1. see the sreenshot image

Here when I pull the data, it contains these columns inside it. I want to make column ‘Control SP’ editable so right now I have added this column into table.columns and made ‘editable’ true and its working.
What I want to know is, if I want to make it via ‘value change script’. How do I convert column from v,alue to object. e.g, right now CONTROL SP: 253, and I want to make it like CONTROL SP.value = 253 & CONTROL SP.editable = true.
So everytime new value comes into table.data, it should convert this column into object and add this 2 props within it. How can I make it?

#2. Right now I made table.column[columnIndex].editable = true and when I update a value of any row from that column, it accepts the value with help of onEditCellCommit event and later upon pressing Confirm Edit I write in to DB with following script:

	table = self.getSibling("Table")
	updatedData = []
	j = 0
	
	#pulling updated values from table and putting into a list
	for i in range (len(table.props.data)):
		updatedData.append(table.props.data[i]['CONTROL SP'])
	
	while j<(len(table.props.data)):
		newValue = updatedData[j]
		ID = table.props.data[j]['ID']
		recipeID = self.getSibling("Dropdown").props.value
			
		params = {}
		params['id'] = ID
		params['recipeId'] = recipeID
		params['newValue'] = newValue
	
		system.db.runNamedQuery('ProjName', 'UpdateQueries/ControlSetpoints', params)
		j+=1
	
	table.refreshBinding("props.data")

And I have created a Update named query to update values inside DB. Is this correct way to do it?

########## System Details ##########

  1. Windows: Windows 10 Pro, 64-Bit
  2. Ignition: 8.1.0

Thanks in advance!

I would recommend against trying to do this with a 'value change' script - instead, just add a transform to your data fetch.

If you're pulling the data out of a database already, then it should be fairly easy to write a transform - something like the process defined here (although that post assumes your data is coming in as a dataset, not a json array):


I don't see any big problems with your script. Coping the values into the updatedData list and then looping over that list is unnecessary - you could just loop through the table's data array directly:

	table = self.getSibling("Table")	
	recipeID = self.getSibling("Dropdown").props.value

	#pulling updated values from table and putting into a list
	for row in table.props.data:
		newValue = row['CONTROL SP']
		ID = row['ID']
			
		params = {
			"id": ID,
			"recipeId": recipeId,
			"newValue": newValue
		}
		
		system.db.runNamedQuery('ProjName', 'UpdateQueries/ControlSetpoints', params)
	
	table.refreshBinding("props.data")
1 Like