PDA

View Full Version : [CLOSED] Editor Field Mapping with component column



PoloTheMonk
Jun 06, 2014, 2:27 PM
Hi,
as in your example http://examples2.ext.net/#/GridPanel/Data_Presentation/Editor_Field_Mapping/ I want to replicate the same with component column but it doesn't work because "renderer" event is not on combo object.

I must use component column because I want "editor" always activates

Here code example

Many thanks,
Polo



<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.stStatoConsuntivazione.DataSource = Department2.GetAll();
this.stStatoConsuntivazione.DataBind();
this.Store1.DataSource = Employee.GetAll();
this.Store1.DataBind();
}
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public Department2 Department { get; set; }
public int DepartmentId
{
get { return this.Department != null ? this.Department.ID : -1; }
}
public static List<Employee> GetAll()
{
return new List<Employee>
{
new Employee
{
ID = 1,
Name = "Nancy",
Surname = "Davolio",
Department = Department2.GetAll()[0]
},
new Employee
{
ID = 2,
Name = "Andrew",
Surname = "Fuller",
Department = Department2.GetAll()[2]
}
};
}
}
public class Department2
{
public int ID { get; set; }
public string NAME { get; set; }
public static List<Department2> GetAll()
{
return new List<Department2>
{
new Department2 {ID = 4, NAME = "4 Department A"},
new Department2 {ID = 5, NAME = "5 Department B"},
new Department2 {ID = 6, NAME = "6 Department C"}
};
}
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Editor Field Mapping - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
<script>
var department2Renderer = function (value) {
var r = App.stStatoConsuntivazione.getById(value);
if (Ext.isEmpty(r)) {
return "";
}
return r.data.NAME;
};
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Store ID="stStatoConsuntivazione" runat="server">
<Model>
<ext:Model ID="Model3" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="CODE" Type="String" Mapping="ID" />
<ext:ModelField Name="NAME" Type="String" Mapping="NAME" />
</Fields>
</ext:Model>
</Model>
</ext:Store>

<ext:GridPanel ID="GridPanel1"
Height="100"
runat="server"
Title="List"
Icon="Application">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model2" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Surname" />
<ext:ModelField Name="DepartmentId" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
<ext:Column ID="Column2" runat="server" Text="NAME" DataIndex="Name" />
<ext:Column ID="Column3" runat="server" Text="SURNAME" DataIndex="Surname" />
<ext:ComponentColumn runat="server" ID="Column4" Text="DEPARTMENT" DataIndex="DepartmentId" Width="240" Editor="true">
<Renderer Fn="department2Renderer"></Renderer>
<Component>
<ext:ComboBox ID="ComboBox2"
runat="server"
Editable="false"
StoreID="stStatoConsuntivazione"
DisplayField="NAME"
ValueField="CODE">
</ext:ComboBox>
</Component>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>

Daniil
Jun 06, 2014, 3:21 PM
Hi @PoloTheMonk,

I don't think you need a Renderer.

Please remove the Renderer and set the String type for the DepartmentId

<ext:ModelField Name="DepartmentId" Type="String" />
or

<ext:ModelField Name="CODE" Type="Int" Mapping="ID" />

In other words, these ModelFields should have the same type.

PoloTheMonk
Jun 06, 2014, 4:21 PM
It works!!!!

Thanks,
Polo


Hi @PoloTheMonk,

I don't think you need a Renderer.

Please remove the Renderer and set the String type for the DepartmentId

<ext:ModelField Name="DepartmentId" Type="String" />
or

<ext:ModelField Name="CODE" Type="Int" Mapping="ID" />

In other words, these ModelFields should have the same type.