3.2.0

How can I make Context Menu in version 2.0 b2?

i found this code at http://www.activewidgets.com/javascript.forum.1933.17/how-can-i-make-context.html
//set the action to handle the contextmenu 
    function oncontextmenu(event) 
    { 
        event.cancelBubble = true; 
        event.returnValue = false; 
        this.action("contextmenu"); 
    } 
   // assign the event handler to the cell template prototype 
    Active.Templates.Text.prototype.setEvent("oncontextmenu", oncontextmenu); 
     
    // create action handler for the right click context menu 
    grid.setAction("contextmenu", function(src){ showmenu(event,getMenuHeader()+menu);return false;});


but v2 has removed get/setAction methods

How can I make Context Menu in version 2.0?
or
How can I customize Event?
xiaohong
December 10,
First, do you know how to make your own AW objects?

If so, I suggest that you create a List object, populate it with your specific menu items, set the height to the number of rows * the row height. Then set the X Y coordinates to where your mouse is. Set an event handeler to handel the item clicks that will do the work of the menu. Then render it to the page. I provided these instructions because you are going to learn a lot more about the controls by creating this yourself then you will from me writing the control for you. With 2.0 this is a very easy control to create, I did it in about an hour and made it generic so that I pass in an array for the menu items and an array of Javascript strings to execute when menu items are clicked.
Jim Hunter
December 12,
Jim -

Would you mind to please publish what you did "as is" ? Learning by example is also a good way to learn.

Philippe Marzin
December 12,
Jim
thank you very much,I know how to create a menu by a div or table...,my problem is how I know the right button clicked?
//in version 1.0 this code will catch right button clicked event
var row = new Active.Templates.Row; 
row.setEvent("oncontextmenu", function(){this.action("myAction")}); 
obj.setTemplate("row", row); 
obj.setAction("myAction", function(){alert('Hello')});
xiaohong
December 13,
This will work:

obj.setEvent("oncontextmenu", "yourfunction(); return false");


I didn't work out the details of knowing which object that you want to attach the event to, I would think it would be the row object. If you want to attach it to the row use obj.getRowTemplate().setEvent.... but I would think you would want to attach it to the grid and access the selected row property to know what the current;y selected row was without changing it via the right click. Just my thoughts...
Jim Hunter
December 13,
I use the following to capture the right-click on the grid:

jobgrid.onRowMouseUp = function(event, index){
if (event.button != 2) return;
writeContextMenu(index);
showContextMenu(event);
};

Here, event.button == 2 for a right-click, index is the index of the row that was clicked.
LostInSpace
December 14,
Jim ,your thoughts is right, i want to access the selected row and do something with it. thank you.
I'v tryed
obj.setEvent("oncontextmenu", "yourfunction(); return false");

and
jobgrid.onRowMouseUp = function(event, index){
if (event.button != 2) return;
writeContextMenu(index);
showContextMenu(event);
};


they all worked.
LostInSpace,and thank you too
xiaohong
December 14,
Has anyone tried to do a context menu triggered off of a Ctrl-Right-Click? I think I am going to need to do it but have not yet tried it. Alex, do you have any properties that would give us keystate? Might be a good addition to the grid if we can come up with a way to do it.
Jim Hunter (www.FriendsOfAW.com)
March 10,
Turned out it is very simple. There is a boolean that you can check to see if the Ctrl key is pressed. This seems to work in IE/FF/Mozilla so I guess borwsers are supporting this. There are 3 different booleans that you can check to see if modifier keys are pressed:

event.ctrlKey
  event.shiftKey
  event.altKey


to use these in your context menu, make this simple change to the above example:

obj.setEvent("oncontextmenu", "if (event.ctrlKey) {yourfunction();} return false");
Jim Hunter (www.FriendsOfAW.com)
March 10,

This topic is archived.

See also:


Back to support forum