PDA

View Full Version : [CLOSED] Ext.Net 2.1 Store's model with mappings



Leonid_Veriga
Jul 03, 2013, 11:54 AM
Hello.

I use source code form trunk brunch, revision 5229. I have store's model with mapping. For fields, which has mapping, data is not loading on client. Please see example below.



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

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

<script runat="server">
protected override void OnLoad(EventArgs e)
{
var test = new int[10];
var rnd = new Random();
var _i = 0;
this.Store1.DataSource = test.Select(s => new
{
Id = ++_i,
Id2 = _i,
Name = "Name_" + rnd.Next(100),
Name2 = "Name2_" + rnd.Next(100)
});
this.Store1.DataBind();
}
</script>

<!DOCTYPE html>

<html>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="700"
Height="310">
<Store>
<ext:Store ID="Store1" runat="server" AutoLoad="true">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="Id">
<Fields>
<ext:ModelField Name="Id" Type="Int" />
<ext:ModelField Name="ID" Mapping="Id2" Type="Int" UseNull="true" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Test_Name2" Mapping="Name2" />

</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" Text="ID" DataIndex="Id" Flex="1" />
<ext:Column ID="Column2" runat="server" Text="ID2" DataIndex="ID" Flex="1" />
<ext:Column ID="Column5" runat="server" Text="Name" DataIndex="Name" Flex="1" />
<ext:Column ID="Column6" runat="server" Text="Name2" DataIndex="Test_Name2" Flex="1" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>


Could you, please, suggest a way to fix this issue?

Best regards.

Daniil
Jul 03, 2013, 1:04 PM
Hi,

You should use Data instead DataSource.

this.Store1.Data = test.Select(s => new
{
Id = ++_i,
Id2 = _i,
Name = "Name_" + rnd.Next(100),
Name2 = "Name2_" + rnd.Next(100)
});

Or use ServerMapping isntead of Mapping.

<ext:ModelField Name="ID" ServerMapping="Id2" Type="Int" UseNull="true" />
<ext:ModelField Name="Test_Name2" ServerMapping="Name2" />

Leonid_Veriga
Jul 04, 2013, 8:10 AM
ServerMapping attribute works for me. Thank you.