[CLOSED] GridPanel - ModelField - Mapping

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] GridPanel - ModelField - Mapping

    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.
    Last edited by Daniil; Jul 08, 2014 at 1:04 PM. Reason: [CLOSED]
  2. #2
    Let me know whether https://examples2.ext.net/#/GridPane..._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.
  3. #3
    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.
    https://examples2.ext.net/#/search/HasMany
  4. #4
    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.
  5. #5
    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'.
  6. #6
    Attachment 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; }
        }
    }
    Last edited by RCN; Jul 07, 2014 at 5:09 PM.
  7. #7
    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" />

  8. #8
    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.
    Last edited by RCN; Jul 07, 2014 at 5:23 PM.
  9. #9
    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.
  10. #10
    Ok, without Type="String" works. Thank you both!
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Mapping on ModelField
    By ptrourke in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 18, 2013, 12:45 AM
  2. ext:ModelField Mapping attribute not working
    By jbarbeau in forum 2.x Help
    Replies: 5
    Last Post: Jan 14, 2013, 10:01 AM
  3. Gridpanel, server mapping
    By myaso in forum 2.x Help
    Replies: 4
    Last Post: Nov 29, 2012, 12:59 AM
  4. [CLOSED] Mapping gridpanel to complex store
    By tlfdesarrollo in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 26, 2012, 4:53 AM
  5. [CLOSED] GridPanel Editor field mapping problem
    By kenanhancer in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 01, 2011, 7:42 AM

Tags for this Thread

Posting Permissions