# Not able to edit perspective table cells after applying the color transform script

**URL:** <https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060>\
**Category:** Ignition\
**Created:** [October 18, 2021, 3:26pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060 "2021-10-18T15:26:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 18, 2021, 3:26pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/1 "2021-10-18T15:26:37Z")

</div>

Hello everyone,

I have a perspective table with an event script configured on “onEditCellCommit”.

```auto
	#GET EDITED DATA DETAILS
	rowIndex=event.row # row number of the commit
	colName=event.column # column name of the commit
	newValue=event.value
	data = self.props.data # Dataset [86R ? 8C]
	pds = system.dataset.toPyDataSet(data) # <PyDataset rows:86 cols:8>
	newData = system.dataset.setValue(data, rowIndex,colName,newValue)
	# update property that is binded to the table
	self.view.custom.part.spec.data = newData
	

```

The table data is also bound to a dataset and I wrote the script below for cell coloring transformation:

```auto
	output_json = []
	style_red = {"classes": "CellColor/AboveHigh"}
	style_green = {"classes": "CellColor/Between"}
	style_yellow = {"classes": "CellColor/BelowLow"}
		
	for row in range(value.getRowCount()):
		row_object = {}
		for col in value.getColumnNames():   
			cell_object={}
			cell_style={}
			cell_object['value']=value.getValueAt(row,col)
			if col == 'process_value':
				if value.getValueAt(row,col)>=value.getValueAt(row, 'low_limit') and value.getValueAt(row,col)<= value.getValueAt(row, 'high_limit'):
					cell_style= style_green
				elif value.getValueAt(row,col)>value.getValueAt(row, 'high_limit'):
					cell_style= style_red
				elif value.getValueAt(row,col)<value.getValueAt(row, 'low_limit'):
					cell_style= style_yellow						
			cell_object['style']=cell_style
			row_object[col]=cell_object				
		output_json.append(row_object)		
	return output_json

```

**The problem is that I am not able to edit the cell once I have the color script on it. It is working without cell coloring but not with that. I get an error:**

TypeError: toPyDataSet(): 1st arg can’t be coerced to com.inductive automation.ignition.common.Dataset

**I am thinking the problem is with the color script as it does not capture the new data to do the transformation on that but not sure how to fix this and would appreciate your help/suggestions in this regard.**

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 18, 2021, 3:54pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/2 "2021-10-18T15:54:16Z")

</div>

Is that the whole thing ?  
The only place where you use `toPyDataSet()` is in the first part:  
`pds = system.dataset.toPyDataSet(data)`.  
But you don’t seem to be using that `pds` variable you initialized…

My suggestion to you: comment out that line and see what’s up.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 18, 2021, 4:00pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/3 "2021-10-18T16:00:02Z")

</div>

You are correct. I am not using pds anywhere else in “onEditCellCommit”. Commented that sentence but I still get that error.

**line 12, in runAction**  
**TypeError: setValue(): 1st arg can’t be coerced to com.inductiveautomation.ignition.common.Dataset**

Line 12: newData = system.dataset.setValue(data, rowIndex,colName,newValue)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 19, 2021, 9:22am UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/4 "2021-10-19T09:22:33Z")

</div>

After trying myself with a dataset, I get the same error. It appears the dataset is actually of type `class com.inductiveautomation.ignition.common.JsonDataset`.  
converting to a `pyDataSet` amd back with `system.dataset.toPyDataSet()` and `system.dataset.toDataSet()` still gives a `JsonDataset`… don’t ask me why.

BUT, If you convert to a `PyDataSet`, you can then use `setValue()` on it, which does return a `BasicDataSet`.

This is all very confusing. I fail to see why my dataset was a legal argument for `toPyDataSet` but not for `setValue()`.

Can you try to log/print the result of `type(data)` ?

edit:  
Wait, I tried again, and was actually able to use `setValue()` on my inital dataset - no idea what I messed up the first time.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 19, 2021, 9:39am UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/5 "2021-10-19T09:39:03Z")

</div>

I tried to set up something that looks like what I think you have:  
Made a view with a table, bound it’s `props.data` property to a query with `dataset` as return type, then added that script on its `onClick` event:

```python
data = self.props.data	
data = system.dataset.setValue(data, 0, 'col_name', 21)
self.props.data = data	
self.getSibling("Label").props.text = type(data)

```

This works as expected. The initial type of the dataset is `BasicStreamingDataSet`, which works with `setValue()`, which in turn returns a `BasicDataSet`.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 19, 2021, 12:28pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/6 "2021-10-19T12:28:42Z")

</div>

Thank you very much, Pascal. Appreciate the valuable time and information you provided.  
Did you use cell coloring after your script? If yes, was it working?

I am able to edit the cell without color, but as soon as I add color transform I get the error when I want to edit the cell. I am thinking the problem is with the cell color transform script not on the edit cell script.

Just for reference, I am writing them here again:

**OnEdittCellCommit Script:**

```auto
	#GET EDITED DATA DETAILS
	#######################################################
	rowIndex=event.row # row number of the commit
	colName=event.column # column name of the commit
	newValue=event.value
	data = self.props.data # Dataset [86R ? 8C]
	pds = system.dataset.toPyDataSet(data) # <PyDataset rows:86 cols:8>
	newData = system.dataset.setValue(pds, rowIndex,colName,newValue)
	# update property that is binded to the table
	self.view.custom.part.spec.data = newData

```

**CellColorTransform Script on property binding:**

```auto
	data=[]
	style_red = {"classes": "CellColor/AboveHigh"}
	style_green = {"classes": "CellColor/Between"}
	style_yellow = {"classes": "CellColor/BelowLow"}
		
	for row in range(value.getRowCount()):
		row_object = {}
		for col in value.getColumnNames():   
			cell_object={}
			cell_style={}
			cell_object['value']=value.getValueAt(row,col)
			if col == 'process_value':
				if value.getValueAt(row,col)>=value.getValueAt(row, 'low_limit') and value.getValueAt(row,col)<= value.getValueAt(row, 'high_limit'):
					cell_style= style_green
				elif value.getValueAt(row,col)>value.getValueAt(row, 'high_limit'):
					cell_style= style_red
				elif value.getValueAt(row,col)<value.getValueAt(row, 'low_limit'):
					cell_style= style_yellow						
			cell_object['style']=cell_style
			row_object[col]=cell_object				
		data.append(row_object)		
	return data

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 19, 2021, 12:42pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/7 "2021-10-19T12:42:16Z")

</div>

No, I only checked the types of the datasets I got at different stages, and which ones I could pass to `setValue()`.  
I don’t think the coloring script has anything to do with your issue.  
Did you try to get the type of `data` ?  
You can print `type(data)` to the console with ‘system.perspective.print()’, send it to a custom property of your table, or display it in a label.  
This might show you why it’s not working.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 19, 2021, 12:47pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/8 "2021-10-19T12:47:48Z")

</div>

**data = self.props.data**

is class . **JsonDataset**

and

**pds = system.dataset.toPyDataSet(data)**

is class.script.builtin.DatasetUtilities$PyDataSet

_ **Edit:** _

I print this again but I got different results for data!!!

```auto
	data = self.props.data # Dataset [86R ? 8C]
	system.perspective.print(type(data))
	
	pds = system.dataset.toPyDataSet(data) # <PyDataset rows:86 cols:8>
	system.perspective.print(type(pds))
	
	pdsds=system.dataset.toDataSet(pds)
	system.perspective.print(type(pdsds))

```

- class com.inductiveautomation.ignition.common. **BasicDataset**
- class com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet
- class com.inductiveautomation.ignition.common.BasicDataset

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 19, 2021, 1:11pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/9 "2021-10-19T13:11:54Z")

</div>

Those should be legal first arg to `setValue()`…

Can you try trimming your script to the bare minimum ?  
Maybe add a button with an onclick event script as such:

```python
data = self.getSibling("table").props.data #replace table with the name of your actual table
system.dataset.setValue(data, 0, 'name_of_a_column', 42)

```

Then try clicking it in preview mode ?

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 19, 2021, 1:46pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/10 "2021-10-19T13:46:02Z")

</div>

I do not get any errors, however, I do not see the changes on the table as well!

```auto
	data=self.getSibling("specTable").props.data
	system.dataset.setValue(data, 5, 'process_value', 5)
	system.perspective.print('This Works')

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 19, 2021, 1:52pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/11 "2021-10-19T13:52:11Z")

</div>

That’s normal, datasets are immutable. `setValue()` returns a new dataset with the modified value.  
If you want the change to be reflected on the table, you need to do

```python
self.props.data = system.dataset.setValue(self.props.data, 5, 'process_value', 5)

```

If you do not get any error there, then there’s something else going on.  
Try going back to `onEditCellCommit` event, start with the bare minimum, and add from that. When you start getting errors, you’ve reached your problem.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [October 20, 2021, 2:49pm UTC](https://forum.inductiveautomation.com/t/not-able-to-edit-perspective-table-cells-after-applying-the-color-transform-script/52060/12 "2021-10-20T14:49:09Z")

</div>

So @cmallonee has replied to my question in another thread so I am posting his solution here for further refrences:

That solved the issue 🙂 Thank you @cmallonee !

> [@Change style of cell (component Table) via script - Perspective](https://forum.inductiveautomation.com/t/change-style-of-cell-component-table-via-script-perspective/44573/15):
>
> > [@Change style of cell (component Table) via script - Perspective](https://forum.inductiveautomation.com/t/change-style-of-cell-component-table-via-script-perspective/44573/14):
> >
> > as soon as I apply the cell color to that script, I get this error:
> > 
> > > **setValue(): 1st arg can’t be coerced to com.inductiveautomation.ignition.common.Dataset**
> 
> This is because the data of the table is a list - not a Dataset. It’s important to remember that targeted cell styling is not compatible with datasets, so you previously converted the `data` property of the table to a list of objects in order to apply styling.
> 
> You’re encountering this error because you’re treating your data in an inadvisable manner. I recommend only having one data source for area of data. In your current code, you’re treating a `view.custom.part.spec.data` as the source for your table, but then you’re treating the table as the basis for updating the view property. Try this instead:
> 
> ```auto
> rowIndex=event.row # row number of the commit
> colName=event.column # column name of the commit
> newValue=event.value
> # Below, I've referenced the source-of-truth dataset instead of the "translated" props.data of the Table
> data = self.view.custom.part.spec.data # Dataset [86R ? 8C]	
> newData = system.dataset.setValue(data, rowIndex,colName,newValue)
> self.view.custom.part.spec.data = newData
> 
> ```
> 
> Even this approach, however, assumes that the custom property is not a binding, which I suspect it is. If that property is the result of a binding, then you should be editing whatever source drives that binding (perhaps a query to update a SQL table).
