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.