# Perspective Table Edit certain cells and write into DB

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-edit-certain-cells-and-write-into-db/40917>\
**Category:** Ignition\
**Tags:** perspective, ignition80\
**Created:** [November 24, 2020, 10:39am UTC](https://forum.inductiveautomation.com/t/perspective-table-edit-certain-cells-and-write-into-db/40917 "2020-11-24T10:39:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [November 24, 2020, 10:39am UTC](https://forum.inductiveautomation.com/t/perspective-table-edit-certain-cells-and-write-into-db/40917/1 "2020-11-24T10:39:06Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/67a1a9cae30eea43a9859b01fd895d9983da9172.png)

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:

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 24, 2020, 4:05pm UTC](https://forum.inductiveautomation.com/t/perspective-table-edit-certain-cells-and-write-into-db/40917/2 "2020-11-24T16:05:40Z")

</div>

> [@Gaurav.Shitole](#):
>
> How do I make certain cell ‘editable’ automatically when the table.props.data changes

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):

> [@Perspective Table - Invididual Cell Conditional Formatting](http://forum.inductiveautomation.com/t/perspective-table-invididual-cell-conditional-formatting/39371/4):
>
> A maybe more maintainable variation, if you ever intend on adding other columns you need to style: def cc\_msval(v, r, c): style\_orange = {"backgroundColor": "#F7901D"} style\_green = {"backgroundColor": "#00AA00"} return { "value": v.getValueAt(r, c), "style": style\_orange if v.getValueAt(r, c) \< 95 else style\_green } transforms = { "CC\_msval": cc\_msval } return [ { value.getColumnName(col): transforms.get(value.getColumnName(col), lambda v, r, c: v.getValueAt(r, c))(v…

* * *

> [@Gaurav.Shitole](#):
>
> I have created a script to write updated values into DB, but not sure if its a safe and standard way.

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:

```python
	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")

```
