[CLOSED] Bug in Store Mapping

  1. #1

    [CLOSED] Bug in Store Mapping

    Hi,

    I have been following this example to use a ComboBox in an editable grid.

    The example runs correctly on my computer. However, if you add a Mapping to the ID field in the store, it stops working. I.e.

    Change this:

    <ext:Store ID="StoreCombo" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="ID">
                <Fields>
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="Name" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    to this:

    <ext:Store ID="StoreCombo" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="OtherID">
                <Fields>
                    <ext:RecordField Name="OtherID" Mapping="ID" />
                    <ext:RecordField Name="Name" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    And update the ComboBox ValueField attribute to "OtherID" as well, making the full example:

    <%@ 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.StoreCombo.DataSource = Department.GetAll();
            this.StoreCombo.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 Department 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 = Department.GetAll()[0]
                                   },
                               new Employee
                                   {
                                       ID = 2,
                                       Name = "Andrew",
                                       Surname = "Fuller",
                                       Department = Department.GetAll()[2]
                                   }
                           };
            }
        }
    
    
        public class Department
        {
            public int ID { get; set; }
            public string Name { get; set; }
    
    
            public static List<Department> GetAll()
            {
                return new List<Department>
                           {
                               new Department {ID = 1, Name = "Department A"},
                               new Department {ID = 2, Name = "Department B"},
                               new Department {ID = 3, Name = "Department C"}
                           };
            }
        }
    </script>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Field Mapping - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    
    
        <script type="text/javascript">
            var departmentRenderer = function (value) {
                var r = StoreCombo.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="StoreCombo" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="OtherID">
                        <Fields>
                            <ext:RecordField Name="OtherID" Mapping="ID" />
                            <ext:RecordField Name="Name" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Surname" />
                            <ext:RecordField Name="DepartmentId" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel ID="GridPanel1" 
                EnableViewState="true" 
                AutoHeight="true" 
                runat="server"
                StoreID="Store1" 
                Title="List" 
                Icon="Application">
                <ColumnModel ID="ColumnModel1" runat="server">
                    
                    <Columns>
                        <ext:Column Header="ID" DataIndex="ID" />
                        <ext:Column Header="NAME" DataIndex="Name" />
                        <ext:Column Header="SURNAME" DataIndex="Surname" />
                        <ext:Column DataIndex="DepartmentId" Header="Department" Width="240">
                            <Renderer Fn="departmentRenderer" />
                            <Editor>                        
                                <ext:ComboBox ID="ComboBox1" 
                                    runat="server" 
                                    Shadow="Drop" 
                                    Mode="Local" 
                                    TriggerAction="All" 
                                    ForceSelection="true"
                                    StoreID="StoreCombo" 
                                    DisplayField="Name" 
                                    ValueField="OtherID"
                                    />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask Msg="Loading" ShowMask="true" />
            </ext:GridPanel>
        </form>
    </body>
    </html>
    When you add in this mapping, it causes the getById function to no longer work correctly and thus you can't create the custom renderer for ComboBoxes in editable grids with a mapping on the store fields.

    Thanks
    Last edited by Daniil; Jun 30, 2011 at 12:20 PM. Reason: [CLOSED]
  2. #2
    Hi,

    IDProperty must be "ID" still because it is property name in the raw object
    Name of the property within a row object that contains a record identifier value.
  3. #3
    Ok, thanks for that.

Similar Threads

  1. ListFilter_Remote with Mapping
    By howardyin in forum 2.x Help
    Replies: 0
    Last Post: Apr 28, 2012, 4:03 AM
  2. [CLOSED] getRecordsValues now uses Mapping instead of Name
    By wazige in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 07, 2011, 1:54 PM
  3. Datatable and Store columns mapping
    By QualityCode in forum 1.x Help
    Replies: 0
    Last Post: Dec 16, 2010, 8:45 PM
  4. [CLOSED] Data Store not updating record mapping from codebehind
    By sadaf in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 08, 2010, 4:42 PM
  5. mapping more complex objects to a Store
    By principal_X in forum 1.x Help
    Replies: 2
    Last Post: Jan 26, 2009, 6:16 PM

Tags for this Thread

Posting Permissions