Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Jigar on Jul 18, 2009 08:32
open dhtmlx forum
Context Menu

Hello,

Can I have context menu options popped when I drag and drop on an element. Basically I want to give user an option of copy files or move files when user drag and drops.
Answer posted by Alex (support) on Jul 20, 2009 02:14

hello,

Menu has showContextMenu(x,y) that allows to show context menu in a certain position. Using onDrag event handler you can apply the following approach:

when onDrag is occurs, you should:

1) save source and target items ids

2) show context menu

3) deny drag

When menu item is clicked, you should enable/disable mercy drag and hide menu:

menu = new dhtmlXMenuObject(null,"standard");
 menu.renderAsContextMenu();
 menu.attachEvent("onClick",onButtonClick);
 
 var showMenu = 1;
 var target_id = 0;
 var source_id = 0;
 
 tree.attachEvent("onDrag",function(sid,tid){
  target_id = tid;
  source_id = sid
  if(!showMenu) return true
  menu.showContextMenu(X,Y)
  return false
 })
 function onButtonClick(menuitemId,type){
  if(menuitemId=="copy") tree.enableMercyDrag(true)
  else tree.enableMercyDrag(false)
  showMenu = 0
  tree.moveItem(source_id,"item_child",target_id)
  menu.hideContextMenu()
  showMenu = 1
 }


Answer posted by Jigar on Jul 21, 2009 04:37
Thanks for the solution. I have used "moveRowTo" function to move or copy data. If the user selects copy then we need to insert data into database while if user selects move we just need to update the database. I tried using "setOnBeforeUpdateHandler" and manually set copy as true (using code - projDetailsGrid.setUserData("", "copy", "true")). But on the server if I perform request.getParameter("copy") it give me null. How should I inform servlet about the operation performed( copy or move).

Thanks again for continued support. Appreciate it.
Answer posted by Alex (support) on Jul 21, 2009 06:28

setOnBeforeUpdateHandler is called too late to send userdata to the server.

You can use onDrag event instead of it. 

Answer posted by Jigar on Jul 21, 2009 13:41
I have performed this command at the beginning "projDetailsGrid.setUserData("","sample", "1");". Still the servlet cannot recognize the value of sample. It returns null.
Code snippet
            projDetailsGrid.setUserData("","sample", "1");
            .....
            ....
            ... *******Some thing goes here********
           ....
           ....
            myDataProcessor1 = new dataProcessor("xmlJsps/xml_feed_project.jsp?action=data");
            myDataProcessor1.setUpdateMode("cell");
            myDataProcessor1.enableUTFencoding(true);
            myDataProcessor1.setTransactionMode("POST");
            myDataProcessor1.enableDebug(true);
           
and on the server side when i perform
          String sample = request.getParameter("sample");
it give me o/p as null

What can be the reason?
Answer posted by Alex (support) on Jul 22, 2009 02:49

You can check using dataprocessor_debug.js what values are sent to server.

Moreover userdata is set only for a certain row:

projDetailsGrid.setUserData(rowId,"sample", "1");