PDA

View Full Version : [CLOSED] Cell Context Menu for a GridPanel



Dzagana
Feb 01, 2013, 6:53 PM
Hi,
I'm trying to do a copy function for a cell value in a GridPanel.

I could display a context menu, but could not read right clicked cell value after.

So the end result is to be able to copy a value of a cell, which was right clicked.

----------
or alternatively make gridpanel cells selectable (not editable, as it confuses users).

Thank you

Baidaly
Feb 01, 2013, 9:56 PM
Hello!

Take a look at the following example:



<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = this.Data;
this.Store1.DataBind();
}
}

private object[] Data
{
get
{
return new object[]
{
new object[] { "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" },
new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" }
};
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>

<style>
.x-grid-row-over .x-grid-cell-inner {
font-weight : bold;
}
</style>

<script>
var template = '<span style="color:{0};">{1}</span>';

var change = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value);
};

var pctChange = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="600"
Height="350">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="price" Type="Float" />
<ext:ModelField Name="change" Type="Float" />
<ext:ModelField Name="pctChange" Type="Float" />
<ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
<ext:Column runat="server" Text="Price" DataIndex="price">
<Renderer Format="UsMoney" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="change">
<Renderer Fn="change" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="pctChange">
<Renderer Fn="pctChange" />
</ext:Column>
<ext:DateColumn runat="server" Text="Last Updated" DataIndex="lastChange" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" />
</SelectionModel>
<Listeners>
<ItemContextMenu Handler="e.preventDefault(); #{GridContextMenu}.dataRecord = this.store.getAt(index);#{GridContextMenu}.showAt( e.getXY());" ></ItemContextMenu>
</Listeners>
</ext:GridPanel>

<ext:Menu ID="GridContextMenu" runat="server">
<Items>
<ext:MenuItem runat="server" Text="Copy">
<Listeners>
<Click Handler="Ext.Msg.alert(this.parentMenu.dataRecord.data.comp any, 'Copy');" />
</Listeners>
</ext:MenuItem>
<ext:MenuItem runat="server" Text="Paste">
<Listeners>
<Click Handler="Ext.Msg.alert(this.parentMenu.dataRecord.data.comp any, 'Paste');" />
</Listeners>
</ext:MenuItem>
</Items>
</ext:Menu>
</body>
</html>

Dzagana
Feb 01, 2013, 10:18 PM
Thanks, but what i am actually looking is top copy cell value which was right clicked, not the first row value.

So if i right click on "price" field, i need to copy price rather than a company name.

Baidaly
Feb 01, 2013, 11:19 PM
Please, try the following sample:



<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = this.Data;
this.Store1.DataBind();
}
}

private object[] Data
{
get
{
return new object[]
{
new object[] { "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" },
new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" }
};
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>

<style>
.x-grid-row-over .x-grid-cell-inner {
font-weight : bold;
}
</style>

<script>
var template = '<span style="color:{0};">{1}</span>';

var change = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value);
};

var pctChange = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" SourceFormatting="True" />

<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="600"
Height="350">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="price" Type="Float" />
<ext:ModelField Name="change" Type="Float" />
<ext:ModelField Name="pctChange" Type="Float" />
<ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
<ext:Column runat="server" Text="Price" DataIndex="price">
<Renderer Format="UsMoney" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="change">
<Renderer Fn="change" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="pctChange">
<Renderer Fn="pctChange" />
</ext:Column>
<ext:DateColumn runat="server" Text="Last Updated" DataIndex="lastChange" />
</Columns>
</ColumnModel>
<View>
<ext:GridView runat="server">
<Listeners>
<CellContextMenu Handler="
e.preventDefault();
#{GridContextMenu}.cellTextContent = cell.textContent;#{GridContextMenu}.showAt(e.getXY ());"></CellContextMenu>
</Listeners>
</ext:GridView>
</View>
<SelectionModel>
<ext:RowSelectionModel runat="server" />
</SelectionModel>
</ext:GridPanel>

<ext:Menu ID="GridContextMenu" runat="server">
<Items>
<ext:MenuItem runat="server" Text="Copy">
<Listeners>
<Click Handler="Ext.Msg.alert(this.parentMenu.cellTextContent, 'Copy');" />
</Listeners>
</ext:MenuItem>
<ext:MenuItem runat="server" Text="Paste">
<Listeners>
<Click Handler="Ext.Msg.alert(this.parentMenu.cellTextContent, 'Paste');" />
</Listeners>
</ext:MenuItem>
</Items>
</ext:Menu>
</body>
</html>

Dzagana
Mar 06, 2013, 10:16 PM
Awesome!
thank you