Hi,
I have been trying to get the copy() function to work for my WebGrid, but it keeps returning false. Here is my javascript code for capturing the context menu:
//Firefox passes event arg as parameter (evt). If that is null, we'll use window.event (Internet Explorer proprietary)
//Call show menu with menuID
//specify clientX and clientY to get more accurate positioning for this particular layout
//Firefox (W3C) - cancel event
//InternetExplorer (Proprietary) - cancel event
return false;
}
{
//Grab a reference to the ContextMenuItem that was clicked on
var oGrid = igtbl_getGridById("ugContacts");
if(item!=null){
//We'll use the text from the menuitem to decide which operation to perform
oGrid.selectRowRegion(oGrid.Rows.getRow(0), oGrid.Rows.getRow(nRows-1));
break;
oGrid.copy();
case "Export To Excel":
//Because the WebGrid consumes all mouse events, we need to add
//a listener to determine when a mouse click has occured so we can
//close the popup menu appropriately
The "Select All" and "Export to Excel" functions properly, but the copy returns a false when I capture it's return value.
I have a WebGrid in a page, it is hierarchical, and I have CellClickActionDefault set to RowSelect. Here is my UltraWebGrid setup:
oninitializelayout="ugContacts_InitializeLayout"
OnDataBinding="ugContacts_DataBinding">
<Bands>
<igtbl:UltraGridBand>
<AddNewRow Visible="NotSet" View="NotSet"></AddNewRow>
</igtbl:UltraGridBand>
</Bands>
name="UltraWebGrid1" rowheightdefault="-1px" selecttypecelldefault="Extended"
viewtype="Hierarchical" CellPaddingDefault="5" ColWidthDefault="-1px" GridLinesDefault="None"
allowsortingdefault="OnClient" enableclientsiderenumbering="True"
sortcasesensitivedefault="False" CellClickActionDefault="RowSelect">
font-names="Microsoft Sans Serif" font-size="XX-Small" height="560px"
width="100%">
</framestyle>
<Images ImageDirectory="./ig_res/Default/images/">
<CollapseImage Url="igg_sortAsc.gif" />
<ExpandImage Url="igg_sortDesc.gif" />
</Images>
Font-Size="XX-Small" BackColor="#CCCCCC" BorderColor="#0144D0"
BorderStyle="None" BorderWidth="0px">
<Padding Left="3px" />
<BorderDetails ColorLeft="White" ColorTop="White" />
</RowAlternateStyleDefault>
<ClientSideEvents MouseUpHandler="ugContacts_MouseUpHandler" />
<pager>
<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
widthtop="1px" />
</PagerStyle>
</pager>
font-size="XX-Small" Font-Bold="True">
</headerstyledefault>
borderwidth="0px" font-names="Microsoft Sans Serif" font-size="XX-Small">
<padding left="3px" />
<borderdetails colorleft="White" colortop="White" />
</rowstyledefault>
<SelectedRowStyleDefault BackColor="#9FBEEB">
</SelectedRowStyleDefault>
<GroupByBox Hidden="True">
</GroupByBox>
<addnewbox>
Font-Names="Microsoft Sans Serif" Font-Size="XX-Small">
</boxstyle>
</addnewbox>
borderstyle="None">
</activationobject>
<AddNewRowDefault>
<RowStyle Font-Names="Microsoft Sans Serif" Font-Size="XX-Small" />
</AddNewRowDefault>
</displaylayout>
</igtbl:UltraWebGrid>
Am I missing something? Do I have a setting improperly set? Or is this not possible with hierarchical grids?
I appreciate any assistance.
Mark
Try setting your CellClickActionDefault in display layout properties of your grid to select a cell and then add row selectors to your grid to select rows. See if this setting helps zero in on the cell and copy the cell correctly. Note that I have not got the copy functionality working in FF.
Thanks for the suggestions, but they unfortunately didn't work. I still can't get the copy function to work in IE.
I think, especially for FireFox, clipboard operations are not something that the UltraWebGrid can control internally. FireFox is very strict when it comes to permissions and especially clipboard operations.
Still, there are some venues you can try. I think the following thread is especially useful:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21269346.html
[scroll down a lot after the Ads to see the response]
and especially the generic copy function here:
function copy_clip(maintext) { if (window.clipboardData) { // the IE-manier window.clipboardData.setData("Text", maintext); } else if (window.netscape) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; trans.addDataFlavor('text/unicode'); var str = new Object(); var len = new Object(); var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); var copytext=maintext; str.data=copytext; trans.setTransferData("text/unicode",str,copytext.length*2); var clipid=Components.interfaces.nsIClipboard; if (!clip) return false; clip.setData(trans,null,clipid.kGlobalClipboard); } alert("Following info was copied to your clipboard:\n\n" + maintext); return false; } //-->