Context Menu to copy Block of data

I am trying to copy the block of data via context menu option “Copy”.

Following is the code I have:

myGrid.attachEvent("onBlockRightClick",function(block,e)
{
	var menu = new dhtmlXMenuObject();
	menu.renderAsContextMenu();
	menu.addNewChild(null,0, "copy", "Copy", false); 
	menu.showContextMenu(e.clientX, e.clientY);
	menu.attachEvent("onClick",function(id, zoneId, cas)
	{
		if (id === "copy")
		{
			myGrid.setCSVDelimiter(",");
			myGrid.copyBlockToClipboard();
		}
	});
});

Note: I am able to copy via Ctrl+C, but was wondering if I can display a copy option via menu on the selected block and copy data to clipboard.

Please Advise.


Unfortunately the clipboard operations in the dhtmlxGrid can be used only using the ctrl+c/ctrl+v shortcuts.

Thanks Sematik for the clarification. I have another related question:

Is there a compatibility issue between Grouping and copying block data. When I tried to group the data and then copy using selection block(Ctrl+c), I got whole table data sometimes(data of collapsed groups).

Unfortunately the block selection is not available in the grouped grid.

Hey Sematik… I was able to get the cell data from grid using context menu…

Following is what i used for menu:
this.DHTMLXGrid.menu = new dhtmlXMenuObject();
this.DHTMLXGrid.menu.renderAsContextMenu();
this.DHTMLXGrid.menu.addNewChild(null, 0, “copy”, “Copy Cell Data”, false);
this.DHTMLXGrid.menu.setContextMenuHideAllMode(false);
this.DHTMLXGrid.enableContextMenu(this.DHTMLXGrid.menu);
this.DHTMLXGrid.attachEvent(“onKeyPress”, KeyboardCopy);
this.DHTMLXGrid.menu.attachEvent(“onClick”, function(menuitemId, type)
{
OnMenuItemClick(gridInfo);
});


function OnMenuItemClick(gridInfo)
{
var data = window[gridInfo.elementName].DHTMLXGrid.contextID.split("_");
window[gridInfo.elementName].DHTMLXGrid.cellToClipboard(data[0], data[1]);
//window[gridInfo.elementName].DHTMLXGrid.selectCell(data[0]-1, data[1], true, true);// (Commented out)
return true;
}


Above code works fine… But, only when I don’t select or highlight the current cell.

The moment I use following LOC and filter or sort data, the whole logic breaks:
window[gridInfo.elementName].DHTMLXGrid.selectCell(data[0]-1, data[1], true, true);

Reason: Cells shift after sorting or filtering.

Please Advise, how can I select the cell with context menu…

Thanks in advance.

selectCell method uses the row_index not the row id.
You may get the index of the row:
var rowIndex=myGrid.getRowIndex(data[0]);
and use it in the selectCell method:
var rowIndex=window[gridInfo.elementName].DHTMLXGrid.getRowIndex(data[0]);
window[gridInfo.elementName].DHTMLXGrid.selectCell(rowIndex, data[1], true, true);