Power table block entry to a cell

How do you block entry to a certain cell on the onCellEditable function

Can you elaborate on what you mean by “block entry”

You should override the isCellEditable() function to drive the logic of whether a not a cell is…editable, and then only use onCellEdited() after a value has actually been entered by the user.

1 Like

Where the reading column say’s N/A or I can even do it by color(black or blue) then I want to block entry to the certain cell. I just need entrys in the white cells

I miss read your post. I took ‘block entry’ as one concept as in entering a block into a cell. Now I realize you meant preventing a cell from being edited. I guess I’m too use to thinking about block entities in AutoCad. As @PGriffith mentioned, use some logic script in the isCellEditable() function to accomplish this.

i get a indent error when I try to apply this

if colName =="Reading":
			if data.getValueAt(rowIndex,"EquipID" )==0:
		
			return False
	
else:
	
return True

Python, or Jython in this case, is not a freeform language. Whitespace matters. Try something like what I have below.

if colName =="Reading":
	if data.getValueAt(rowIndex,"EquipID" )==0:		
		return False	
else:
                return True

that blocks the whole column not the individual cells

I see, I think.

if colName =="Reading":
	if data.getValueAt(rowIndex,"EquipID" )==0:		
		return False	
	else:
		return True

that worked but I don't understand why. Scripting is a wonderful thing.Thanks for the help

The isCellEditable function is run once for every single cell in the table - and it returns a boolean True/False that says “this cell is editable”.
After verifying that the cell is editable, an editor of some kind will be opened - either just an editable text field, or a dropdown, or a checkbox, etc. After that editor “stops” editing, it will then send the new value “back” to the table - at which point, your custom onCellEdited event needs to fire to actually update the table’s data (or send it back to the database, or write it to tag, or do whatever else it needs to do).

As far as the code goes: Your first if statement narrows the logic down to the ‘Reading’ Column. This excludes all data that is not in that column. The second if statement narrows the logic down to the individual cells. This means that your else statement needs to be aligned with the inner, or second, if statement. If you align the else with the first if statement, you get the entire columns being affected because it doesn’t depend on the second if statement only the first one. The first, or outside, if statement does not have an associated else statement, because it doesn’t matter in your situation. But if it did, you would put another else in the code aligned with that first if statement.

This works below

data = self.data		
	                
	if colName =="Reading":		
		if data.getValueAt(rowIndex,"ReqReading" )==0:		
			return False	
		else:
			return True
	elif colName =="Question":
			return False	
	else:
		return True
1 Like

I would format it like so to help make it readable. You probably will want to google python indent/whitespace conventions online and learn it. Then figure out how you like to layout/format code and be consistent with it. It will help you debug and read the code

data = self.data			                
if colName =="Question":
		return False
elif colName =="Reading":		
	if data.getValueAt(rowIndex,"ReqReading" )==0:		
		return False	
	else:
		return True	
else:
	return True
data = self.data			                
if colName =="Question":
		return False
elif colName =="Reading":		
	return data.getValueAt(rowIndex,"ReqReading" )!=0
else:
	return True
1 Like

After adding other columns, no errors for once. Maybe I got it. Again thanks for all the help. I will google it and see if I understand it better. I will look at reorganizing the code as well. On to the next challenge, printing the power table zoomed in. I can print it just fine but you can barely see it.

data = self.data		
	                
	if colName =="Reading":		
		if data.getValueAt(rowIndex,"ReqReading" )==0:		
			return False	
		else:
			return True
	elif colName =="Question":
			return False	
	elif colName =="Status":
		if data.getValueAt(rowIndex,"EquipID")==0:
			return False
		else:
			return True
	elif colName =="Comments":
		if data.getValueAt(rowIndex,"EquipID")==0:
			return False
		else:
			return True
	else:
		return True
data = self.data
# Don't allow editing in Question column.
if colName == "Question":
	return False
# Allow editing in Reading column if ReqReading column is not zero.
elif colName == "Reading":		
	return data.getValueAt(rowIndex, "ReqReading") != 0
# Allow editing in Status and Comments columns if EquipID column is not zero.
elif colName in ["Status", "Comments"]:
	return data.getValueAt(rowIndex, "EquipID") != 0
# Allow editing in all other columns.
else:
	return True
2 Likes

That worked great. That streamed line the whole thing. Thanks for the help.

I've followed the samples in this post and for some reason I'm only able to make the entire column editable, not individual cells.

I'm using a Power Table with 3 columns, Location, Data, and Reset. Only the Reset column should be editable, then based on the user and if there is no part present in that location (PyDataset[rowIndex][0] == 0), it should allow the cell in the Reset column to be editable. I then clear the adjacent data in the Data column with the onMouseClicked function for the cell in the Reset column. I'm finding that if the result value for the return is False, the cell is still editable.

    pyPP = system.dataset.toPyDataSet(self.PP)
user = system.security.getUsername()

if colName == 'Location':
	return False
	
if colName == 'Data':
	return False
	
if colName == 'Reset':
	if user == 'eng' or user == 'service':
		return pyPP[rowIndex][0] == 0

The way this is written, a pydataset is created and a username call is made for every cell in the table. Perhaps rewrite it like this:

#def isCellEditable(self, [...], value):
	if colName == 'Reset' and self.PP.getValueAt(rowIndex, 0) and system.security.getUsername() in ['eng', 'service']:
		return True
	return False

This version of the script takes advantage of the fact that Python short circuits on false, so the PP dataset is only checked when a cell is in the reset column, and the username is only checked if a part is present. Also, I imagine PP is just a dataset custom property on the power table, so there is no need to create a pydataset; the value can just be obtained directly using the `getValueAt(row, column) method.