PDA

View Full Version : [CLOSED] GridPanel - ModelField - Mapping



jamesand
Jul 07, 2014, 3:03 PM
Hi everyone! I hope you can help me with this.

I have a Store that reads from the database using LINQ. Store.DataSource = List(Of Clients).

The thing is that Clients is associated with Cities. How can I do to show in the GridPanel the name of the city associated? Such as (this doesn't work):


<ext:ModelField Name="CityName" Type="String" Mapping="Cities.CityName" />

Properties of Clients:

- Id
- Name
- City: Object of Cities

I hope I explained myself.

Thanks in advance.

RCN
Jul 07, 2014, 3:12 PM
Let me know whether http://examples2.ext.net/#/GridPanel/Miscellaneous/Custom_Data_Binding/ example helps you.

if it does not fit your needs, please post a complete (but simplified) code sample demonstrating how to reproduce the issue.

Daniil
Jul 07, 2014, 3:17 PM
Hi @jamesand,

So, a Client has many Cities.

This

<ext:ModelField Name="CityName" Type="String" Mapping="Cities.CityName" />



looks that the Client has the only City, but that is not true.

I guess you might be looking for a HasManyAssociation.
http://examples2.ext.net/#/search/HasMany

RCN
Jul 07, 2014, 3:34 PM
Daniil, i agree with you that he might be looking for a HasManyAssociation, but it sounds weird show the name of the city when it's a list of cities.

jamesand
Jul 07, 2014, 3:51 PM
Thank you Raphael and Daniil for your quick responses.

In fact one client has just one city, as Raphael said.

When I write:



<ext:ModelField Name="Cities">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="CityName"/>
</Fields>
</ext:Model>
</Model>
</ext:ModelField>


it crashes saying: 'Ext.Net.ModelField' doesn't have any property which name is 'Model'.

RCN
Jul 07, 2014, 5:28 PM
13351



<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
</head>
<body>
<ext:ResourceManager runat="server" SeparateUIStyles="false" ScriptMode="Development" />
<ext:GridPanel runat="server" Title="Records" Frame="false" Width="500" Height="500 ">
<Store>
<ext:Store AutoLoad="true" ID="_str" runat="server">
<Proxy>
<ext:AjaxProxy Url="/Example/LoadFakeRecords/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="data" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="ID" Type="String" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="City" Type="String">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
</ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Text="ID" DataIndex="ID" runat="server" />
<ext:Column Text="Name" DataIndex="Name" runat="server" />
<ext:Column Text="City" DataIndex="City" runat="server">
<Renderer Handler="return value.Name;" />
</ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
</body>
</html>




namespace RCNBS.Visions.SandBox.Controllers
{
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}

public StoreResult LoadFakeRecords()
{
List<Entity> lst = new List<Entity>();

for (int index = 0; index < 15; index++)
{
lst.Add(new Entity
{
ID = index,
Name = string.Format("Name{0}", index),
City = new City
{
Name = string.Format("City{0}", index)
}
});
}

return new StoreResult(lst, lst.Count());
}
}

public class Entity
{
public int ID { get; set; }

public string Name { get; set; }

public City City { get; set; }
}

public class City
{
public string Name { get; set; }
}
}

Daniil
Jul 07, 2014, 5:50 PM
it crashes saying: 'Ext.Net.ModelField' doesn't have any property which name is 'Model'.

You might use the Ext.NET version which doesn't support that yet.

As an alternative approach for the Raphael's suggestion, if you use a Store's DataSource, this should work:

<ext:ModelField Name="CityName" Type="String" ServerMapping="Cities[0].CityName" />

RCN
Jul 07, 2014, 6:19 PM
Daniil, i do not know why it does not work properly if the set Type="String" on "City" ModelField, as shown below:

Doesn't Work


<ext:ModelField Name="City" Type="String">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
</ext:ModelField>


Doesn't Work


<ext:ModelField Name="City" Type="String">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Name" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:ModelField>


Works


<ext:ModelField Name="City">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Name" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:ModelField>


Works


<ext:ModelField Name="City">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
</ext:ModelField>


I think that "City" ModelField type must be set to "Object", what is done implicitly when no value is set.

Daniil
Jul 08, 2014, 5:31 AM
Yes, the Type should not be String, because it means a .toString() call on the value.

arrayValue.toString();

So, then a result string will be parsed by the inner Model. Something like this:

arrayValue.toString().Name

Type="Object", as well as omitted Type or Type="Value", mean that no conversion will be made with the value.

jamesand
Jul 08, 2014, 1:12 PM
Ok, without Type="String" works. Thank you both!

Khosrou
Mar 12, 2015, 1:45 PM
Hi;
I had same problem and my problem solved by this code:


<ext:ModelField Name="CityName" ServerMapping="Cities.CityName" Type="String" />