PDA

View Full Version : How To Hold The RowData Of A Dynamic Grid In CodeBehind Ext.NET 3.0



Kasani007
Sep 14, 2015, 10:55 AM
How To Hold The RowData Of A Dynamic Grid In CodeBehind Ext.NET 3.0 ?

Daniil
Sep 14, 2015, 1:53 PM
Hi @Kasani007,

I am not sure what exactly you mean under "hold". Please elaborate.

Also it is not entire obvious what is "RowData", but I guess you are dealing with a RowBody plugin?

Kasani007
Sep 15, 2015, 6:17 AM
Actually That What I need exact is

I have a Grid with Rowexpander and in the rowexpander, child grid will display which is related to the main Grid (i had created the child grid dynamically by using Directmethod In Loader of RowExpander),

Now My Requirement Is That By RightClicking On any row of the child grid a menu named "View Info" should Popup and if i click on that menu it should show the Child grid data in a separate window.

Please Help me ...

The Code I Had Written is:

.aspx page
-----------
-----------

<%--Row Expander Code Start--%>
<Plugins>
<ext:RowExpander runat="server">
<Loader runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component">
<LoadMask ShowMask="true" />
<Params>
<ext:Parameter Name="ReceiptForm" Value="this.record.getId('ReceiptFormId')" Mode="Raw" />
</Params>
</Loader>

<DirectEvents>
<BeforeExpand OnEvent="BeforeExpand">
<EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={parentGridPanel.body}" />

<ExtraParams>

<ext:Parameter Name="ReceiptFormId" Value="record.get('ReceiptFormId')" Mode="Raw" />
</ExtraParams>
</BeforeExpand>

</DirectEvents>

</ext:RowExpander>
</Plugins>
<%--Row Expander Code End--%>

.cs file
---------
---------


protected void childGrid_RowSelect(object sender, DirectEventArgs e)
{
int InfoId = e.ExtraParams["InfoId"].ExtractInt32();
}

protected void BeforeExpand(object sender, DirectEventArgs e)
{
int FormId = e.ExtraParams["ReceiptFormId"].ExtractInt32();


}


[DirectMethod]
public string GetGrid() //Dictionary<string, string> parameters
{

Menu rcmViewInfo1 = new Menu();
rcmViewInfo1 .Add(new MenuItem { Text = "View Info", Icon = Icon.ApplicationGet });
if (receiptLineItems != null)
{

List<object> data = new List<object>();

data = dataObjectItems.ToList<object>();

var selectionModel = new RowSelectionModel
{
Mode = SelectionMode.Single,
DirectEvents =
{
Select =
{
// Events="childGrid_RowSelect",

ExtraParams =
{
new Parameter("Infoid", "record.get('InfoId')", ParameterMode.Raw),

}
}
}
};



GridPanel childGrid = new GridPanel
{
// Height = 200,
EnableColumnHide = false,
ContextMenuID = "rcmViewInfo1",

Store =
{
new Store
{
Model = {
new Ext.Net.Model {
IDProperty = "ReceiptFormId",
Fields =
{
new ModelField("InfoId"),
new ModelField("InvoiceDate", ModelFieldType.Date,"M/d hh:mmtt"),
new ModelField("InvoiceAmount"),
new ModelField("PaidAmount"),


}
}
},

DataSource = data
}
},
ColumnModel =
{
Columns =
{
new Column { Text = "Info Id", DataIndex = "InfoId", Width = 150 },
new DateColumn { Text = "Invoice Date", DataIndex = "InvoiceDate", Width = 150 },
new Column { Text = "Invoice Amount", DataIndex = "InvoiceAmount", Width = 150 },
new Column { Text = "Receipt Amount", DataIndex = "PaidAmount", Width = 150 },


}
},
SelectionModel =
{
selectionModel

}
};

return ComponentLoader.ToConfig(childGrid);

}

Daniil
Sep 15, 2015, 7:31 AM
Thank you for the clarification.

I think ContextMenuID = "rcmViewInfo1" is not going to work for your requirement. Please use a GridPanel's or its View's ItemContextMenu listener.

Here is an example.
http://examples.ext.net/#/Action/Basic/Grid

Please ignore the ActionRef stuff. The key points for you are:

1. Defining a Menu as, I guess, you already have.

<ext:Menu ID="ContextMenu" runat="server">
<Items>
...
</Items>
</ext:Menu>

2. Opening it on a row right click.

<ViewConfig>
<Listeners>
<ItemContextMenu Handler="e.stopEvent(); #{ContextMenu}.showAt(e.getXY()); return false;" />
</Listeners>
</ViewConfig>

Kasani007
Sep 15, 2015, 8:59 AM
How Can I Fire The Event childGrid_RowSelect When Right Clicked On The Dynamic ChildGrid (The Answer Is Most Helpful For Me)

Daniil
Sep 15, 2015, 9:10 AM
By default a row is being selected on right click. So, the Select event should fire.

The question how to attach the event in code behind has been answered here.
http://forums.ext.net/showthread.php?60088&p=274869&viewfull=1#post274869

But there is a limitation - a DirectEvent is not going to work for a dynamic control (a child GridPanel) unless it is recreated. You can try either recreating a child GridPanel control on each request or use a client side Select listener + a DirectMethod combination instead of DirectEvent. Personally, I would prefer the second approach with a DirectMethod.

Kasani007
Sep 15, 2015, 9:36 AM
Can You Please Ellobrate How It Is?

Daniil
Sep 15, 2015, 10:08 AM
Please look at the SelectionModel and DirectMethod definitions in this example.

Example

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

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (X.IsAjaxRequest)
{
//We do not need to DataBind on an DirectEvent
return;
}

List<object> data = new List<object>();

for (int i = 1; i <= 10; i++)
{
data.Add(new { ID = "S" + i, Name = "Supplier " + i});
}

this.Store1.DataSource = data;
}

[DirectMethod]
public static string GetGrid(Dictionary<string, string> parameters)
{
// string id = parameters["id"];

List<object> data = new List<object>();

for (int i = 1; i <= 10; i++)
{
data.Add(new { ID = "P" + i, Name = "Product " + i });
}

GridPanel grid = new GridPanel
{
Height = 200,
EnableColumnHide = false,
Store =
{
new Store
{
Model = {
new Model {
IDProperty = "ID",
Fields =
{
new ModelField("ID"),
new ModelField("Name")
}
}
},
DataSource = data
}
},
ColumnModel =
{
Columns =
{
new Column { Text = "Products's Name", DataIndex = "Name", Width = 150 }
}
},
SelectionModel =
{
new RowSelectionModel
{
Listeners =
{
Select =
{
Handler = "App.direct.OnRowSelect(record.getId());"
}
}
}
}
};

return ComponentLoader.ToConfig(grid);
}

[DirectMethod]
public void OnRowSelect(string recordId)
{
X.Msg.Alert("OnRowSelect", "The selected record's id: " + recordId).Show();
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v3 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:GridPanel
runat="server"
Width="600"
Height="450"
DisableSelection="true">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" />
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Supplier" DataIndex="Name" Flex="1" />
</Columns>
</ColumnModel>
<Plugins>
<ext:RowExpander runat="server">
<Loader runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component">
<LoadMask ShowMask="true" />
<Params>
<ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
</Params>
</Loader>
</ext:RowExpander>
</Plugins>
</ext:GridPanel>
</form>
</body>
</html>

Kasani007
Sep 15, 2015, 11:45 AM
Thank You Very very very very Much Daniil

Its Works Well