Selecting a Perspective table row with right-click

Good day folks. This post is sort of the spiritual successor to this Vision post.

my requirement is: given a contextMenu that is opened with rightclick (using the built in meta.contextMenu on a table component) open a popup that receives data from the right-clicked row.

I found that because right-click doesn't select a row in the way left-click does, I can't rely on self.props.selection.selectedRow since it doesn't update when right-clicked. would think that in order to leverage it I'd need to trigger a left-click event.

How would you approach it, given that the extension functions and methods of the table have changed somewhat from vision to perspective? and given this limitation on the right-click method.

  • params: Adds the object of params to pass to the method. Note that positional arguments are not supported.

I had been hoping to leverage a script on the 'onContextMenu' mouse event of the table since it can leverage both the MouseEvent (event) and Component (self). but i'm not sure if there's a method on either I could use. I thought of a very hacky method that translates the x and y of the mouse-event coordinates and 'guesses' the clicked row but it seems... dangerous.

any wisdom or guidance would be well appreciated.

It won't handle a scrolled table, for starters.

I think the topic has come up few times on the forum. I'll see if I can find one.


Here's one or two hacks:

1 Like

Well, This is a fairly substantial change on my setup, but its better than what I was cooking up.
I'm greedy, and I still am interested if the concept of a script-triggered-mouseclick might still be applicable in perspective. It certainly seems to be a more 'elegant' way around the issue, and I do have concerns on performance if I push ahead with the rendered-view method. Papa's got a big table.

This thread really caught my attention, particularly this logic from @jespinmartin1

if event.propertyName == "longValue":
	event.source.requestFocusInWindow()
	def click():
		from java.awt.event import MouseEvent
		from java.lang import System
		target = event.source
		id = MouseEvent.MOUSE_RELEASED
		when = System.currentTimeMillis()
		x = target.getX()
		y = target.getY()
		click = MouseEvent(target, id, when, 0, x, y, 1, False)
		event.source.dispatchEvent(click)
	system.util.invokeLater(click)

if anyone else has experience firing off mouse-events in perspective like this example from vision, let me know! I'm going to play around with the code on the off chance I get lucky and can get it working

You cannot.

Firing off mouse clicks unsolicited in a web browser is exactly equivalent to malware. No browser allows you to do this just by visiting a page.

3 Likes

Ahhh yup. That makes a lot of sense in context. then there has to be some way though that web applications can tie the right-click action to the components they are clicking on.... This is diving too deep down the rabbit hole though. I guess I'll suck it up and code it the hacky way.
I guess passing things along in a message handler won't be all that bad. makes it a little easier to adapt later on when i'll have to put context menus everywhere. thanks for the guidance yall!

Maybe I don't fully understand the problem, but don't allow the contextMenu unless a row is selected. For me, I do this and only if a single row is selected. I actually have a message that tells them to only select a single row.

1 Like

I think this could benefit from the same philosophy I described here, using a separate "Selected" table and toggling between them. Perspective Table select all - #4 by msteele
This would give you more flexibility on how you populate data in your selected table.

1 Like

Update day!

Here's one or two hacks

Unfortunately this was untenable. Worked for some smaller datasets but my half second loads ballooned to 10+ seconds on my table once I scaled up. Had to abandon it.

firing off mouse-events in perspective

This was impossible, as was illustrated

but don't allow the contextMenu unless a row is selected. For me, I do this and only if a single row is selected

This was sort of relevant, and had an interesting corner case. but didn't tackle the locus of the problem having right click interact with the data in the table beneath it.

using a separate "Selected" table and toggling between them.

I couldn't quite connect the dots on this, it went over my head. if you were interested in going into more detail on how to apply it to this challenge I'd be interested.

I built it, I stipulated our customer must left click, then right click. It works, and I'm disappointed. I learned that the 'Copy' right-click is also dependent on a left click before right-click, so at least the deficiency is consistent.

I'll leave this open in case anyone else wanted to contribute. otherwise I'll go lurk in the features/improvements request area

I'll go lurk in the features/improvements request area