Get value of "context menu id" property from grid

Use this board for starting discussions, asking questions, and giving advice on Web programming for the IBM i platform (and predecessors.)
JacobPreston
New User
Posts: 10
Joined: Fri Apr 05, 2019 4:09 pm
First Name: Jacob
Last Name: Preston
Company Name: Preston Software
Contact:

Get value of "context menu id" property from grid

Post by JacobPreston »

I have a grid that will have a different popup menu when a row is right clicked depending on the user.

I have set a variable for the "context menu id" property on the subfile and change it accordingly depending on which user is running the program.

The issue i'm having is determining how to set up the onrowclick for this grid. I tried binding the "value" property for the grid to be the same variable that was bound to the context menu id to retrieve the menu name, but this did not seem to function as I had expected. (PS1022_S is the id of the grid in this example)

Code: Select all

menuName = getElementValue("PS1022_S");
applyProperty(menuName,"user defined data",row);
Is there a way for the onrowclick of the grid that I can retrieve the menu name for the context menu id property to be passed to applyProperty?

Thanks!
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Get value of "context menu id" property from grid

Post by Scott Klement »

Hello Jacob,
JacobPreston wrote:I have a grid that will have a different popup menu when a row is right clicked depending on the user.

I have set a variable for the "context menu id" property on the subfile and change it accordingly depending on which user is running the program.
Up to here, I understand what you're saying. But then the next statement is where I'm struggling to understand:
JacobPreston wrote:The issue i'm having is determining how to set up the onrowclick for this grid. I tried binding the "value" property for the grid to be the same variable that was bound to the context menu id to retrieve the menu name, but this did not seem to function as I had expected. (PS1022_S is the id of the grid in this example)
The Grid widget doesn't use the "value" property, so that's probably why you can't use getElementValue() with it. But, I'm not understanding why you'd want to do that, anyway? Why not just retrieve the context menu id property instead of setting the value to the context menu id's value?
JacobPreston wrote:

Code: Select all

menuName = getElementValue("PS1022_S");
applyProperty(menuName,"user defined data",row);
I also don't understand why you're setting the menu's first "user defined data" to the row value. What does that accomplish? Seems like a weird thing to do.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Get value of "context menu id" property from grid

Post by Scott Klement »

I was thinking about this more, and it occurred to me that the reason you were using "user defined data" was probably because you saw an example where that property was used to pass data from the RPG program to the display... (sorry, sometimes I'm a bit slow.)

In this case, though, you're coding JavaScript that's already in the display so you don't need to do that. Don't get me wrong, it'd work fine... but imho, it's simpler to just use a JavaScript variable.

So my suggestions are:
1) Retrieve the context menu property to determine which menu (if you still need that)
2) Use a JavaScript variable for the last row clicked.

in JavaScript, global variables are created by attaching them to the 'window' object. So if you do window.XXX, you have a global variable named XXX (and you can refer to it simply as 'XXX' if there isn't any other variables with that name.)

For example, your 'onrowclick' could look like this:

Code: Select all

window.lastRowClicked = row;
Then in the menu's "onoptionclick" (run when the user selects an option from the menu) you could do something based on that row. (I don't know what your menu does, so for a really simple example, I'll just show an alert that prints what the user selected)

Code: Select all

var msg = "You selected " + text + " which is value " + value
        + " on row " + lastRowClicked;
alert(msg);        
But, if for some reason you do still need to know the id of the menu for something, you can get it from the context menu id property:

Code: Select all

var menuName = getObj("PS1022_S").pui.properties["context menu id"];
JacobPreston
New User
Posts: 10
Joined: Fri Apr 05, 2019 4:09 pm
First Name: Jacob
Last Name: Preston
Company Name: Preston Software
Contact:

Re: Get value of "context menu id" property from grid

Post by JacobPreston »

Scott Klement wrote:I was thinking about this more, and it occurred to me that the reason you were using "user defined data" was probably because you saw an example where that property was used to pass data from the RPG program to the display... (sorry, sometimes I'm a bit slow.)

In this case, though, you're coding JavaScript that's already in the display so you don't need to do that. Don't get me wrong, it'd work fine... but imho, it's simpler to just use a JavaScript variable.

So my suggestions are:
1) Retrieve the context menu property to determine which menu (if you still need that)
2) Use a JavaScript variable for the last row clicked.

in JavaScript, global variables are created by attaching them to the 'window' object. So if you do window.XXX, you have a global variable named XXX (and you can refer to it simply as 'XXX' if there isn't any other variables with that name.)

For example, your 'onrowclick' could look like this:

Code: Select all

window.lastRowClicked = row;
Then in the menu's "onoptionclick" (run when the user selects an option from the menu) you could do something based on that row. (I don't know what your menu does, so for a really simple example, I'll just show an alert that prints what the user selected)

Code: Select all

var msg = "You selected " + text + " which is value " + value
        + " on row " + lastRowClicked;
alert(msg);        
But, if for some reason you do still need to know the id of the menu for something, you can get it from the context menu id property:

Code: Select all

var menuName = getObj("PS1022_S").pui.properties["context menu id"];
Thanks so much for this useful information. I believe I had seen it in an example a long time ago, so I had just been doing it that way ever since. Appreciate the help!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests