Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tejas Shah on Aug 12, 2008 04:35
open dhtmlx forum
DHTMLX Grid : Column Context Menu

Hi,
I have used following to create the context menu for Column headers.

// Column Header Context Menu Creation : S
var colMenu = new dhtmlXContextMenuObject('120', 0);
colMenu.setContextZone(libTableGrid.hdr,"header"); //attach context menu to grid header
colMenu.menu.loadXML("<%=path%>/xml/context/colMenuOptions.xml");
colMenu.setContextMenuHandler(colMenuClicked);
// Column Header Context Menu Creation : E

Do I need to attach it to the grid as I already have attached the context menu for the data part(CELL) ?????


Now in colMenuClicked() which is handling the click event in menu, I want column id of that column header, How can I get it ???
Please help !!!
Answer posted by Support on Aug 12, 2008 06:56
>>Do I need to attach it to the grid 
Menu attached to the grid will be shown when any cell in data prart of grid has been clicked
If you want to use the same menu for header and data part of grid - using grid.enableContextMenu has sense, in other cases you need not any additional command. 

>>I want column id of that column header, How can I get it 
The context menu handler will return just ID of element , with which setContextZone was called ( "header" in your case ) 
The context menu was used against some HTML element , so it can't provide info about in-grid structures.

Answer posted by Tejas Shah on Aug 12, 2008 07:53
Hi,
     Is there some way or what do I need to change in the corr JS file to get Column Id of column on which the context menu is created ?
Answer posted by Support on Aug 12, 2008 09:41
The next may work in most cases 

colMenu.setContextMenuHandler(colMenuClicked);
function colMenuClicked(menuId,zoneId,zoneObject){
      var cell = mygrid.getFirstParentOfType(zoneObject,"TD");
      if (cell) alert("column index " + cell._cellIndex);
};
Answer posted by Tejas Shah on Aug 13, 2008 02:58
Hi,
    I used your mentioned code, but it is alerting undefined for column index.
    I slightly modified the code like ::

                            var cell = libTableGrid.getFirstParentOfType(zoneObject,"TD");
                                        if (cell) alert("column index " + cell.cellIndex);
    then it is giving always 0 as column index. I want 0 for first column, 1 for second column and so on if I click on Context menu options of Column Header.
 
    Why this happens ?
Answer posted by Support on Aug 14, 2008 02:10
Working sample sent by email.
Answer posted by Tejas Shah on Aug 14, 2008 04:17
Hi,
    I haven't received the sent file, please re-send it. Thanks in Advance.
Answer posted by Support on Aug 15, 2008 02:06
If you still have not receive email, please contact us directly at support@dhtmlx.com