Perspective table disable editing on certain rows

I am using a Perspective application to manage passwords for our various control systems. Based on the user’s rights they will be able to see the password or ‘********’. If they have rights to the password they can edit that row.

In the onCellCommit event I have added the lines below to prevent them updating rows for which they do not have sufficient rights.

	r = event['row']						# The Perspective table row number.
	if not self.props.data[r].canEdit:		# This user is not allowed edit this db table row.
		return						# Do nothing.

This works but it rejects the edit after the event.

How can I deselect the cell by code if the operator selects the cell but doesn’t have authorisation? It would be a line or two to be added to the onSelectionChanged event. Any better ideas?
Many thanks.

You can use the onCellEditStart function to preserve the value pre-edit. In this function, you can simply set props.selection.selectedRow and props.selection.selectedColumn to null to remove the selection as soon as an operator attempts to edit a cell.

Thank you for your reply.

If I use the default table and add this code to the onEditCellStart

	r = event['row']						        # The Perspective table row number.
	if self.props.data[r].city == 'Helsinki':		# This user is not allowed edit this db table row.
		system.perspective.print("Exiting edit.")
		self.props.selection.selectedRow = None
		self.props.selection.selectedColumn = None

… the cell remains in edit mode.
Why?

Interestingly, I have cells, allowEditOn : single-click and the onEditCellStart event is fired when a cell is selected (which doesn’t turn on editing) and again when the cell is clicked a second time (which does turn on cell editing). Why is the event fired the first time?