Complex Serialization and Templates

  1. #1

    Complex Serialization and Templates

    Hi,

    I am using templates in a combo with complex type from the store.

    I was wondering whether it is possible to use them in the template as shown below.

    Shall I use a Mapping ? If yes, how ?


    The store :
    	<ext:Store runat="server" ID="stoUsers" IgnoreExtraFields="true" AutoLoad="false" SerializationMode="Complex">
    	    <Proxy>
    	        <ext:HttpProxy Method="GET" />
    	    </Proxy>
    	    <Reader>
            	<ext:JsonReader Root="Users" TotalProperty="Total" ReaderID="ID">
    	            <Fields>
            	        <ext:RecordField Name="ID" Type="Int" />
    	                <ext:RecordField Name="Name" Type="String" />
            	        <ext:RecordField Name="Address.City" Type="String" />
    	            </Fields>
            	</ext:JsonReader>
    	    </Reader>
    	</ext:Store>

    The combo :
    	<ext:ComboBox runat="server" ID="ddlUsers"
                HideTrigger="true"
                AllowBlank="false"
                ForceSelection="true"
                BlankText="Required Field"
                Width="450"
                StoreID="stoUsers"
                DisplayField="Name" 
                ValueField="ID"
                TypeAhead="false"
                PageSize="10"
                ItemSelector="div.search-item"
                MinChars="1">
               <Template ID="tplUsers" runat="server">
                   <tpl for=".">
                      <div class="search-item">
                         <h3>{Name}</h3>
                         {Address.City}
                      
    
                   </tpl>
               </Template>
            </ext:ComboBox>

    Best Regards.


    Bruno.
  2. #2

    RE: Complex Serialization and Templates

    Hi,

    You can use convert function
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!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>AJAX request to HttpHander returns Json - Coolite Toolkit Example</title>
        
        <script runat="server">
            
            protected void Page_Load(object sender, EventArgs e)
            {
                List<Customer> list = new List<Customer>(5);
    
                for (int i = 0; i < 5; i++)
                {
                    Customer customer = new Customer();
                    customer.ID = i;
                    customer.FirstName = "FirstName" + i;
                    customer.LastName = "LastName" + i;
                    customer.Company = "Company" + i;
                    
                    Address address = new Address();
                    address.StreetAddress = "Street"+i;
                    address.City = "City" + i;
                    customer.Address = address;
    
                    list.Add(customer);
                }
    
                Store1.DataSource = list;
                Store1.DataBind();
            }
            
            
            public class Customer
            {
                public int ID { get; set; }
                public string FirstName { get; set; }
                public string LastName { get; set; }
                public string Company { get; set; }
                public Address Address { get; set; }
            }
    
            public class Address
            {
                public string StreetAddress { get; set; }
                public string City { get; set; }
                public Country Country { get; set; }
            }
    
            public class Country
            {
                public string Name { get; set; }
                public string Code { get; set; }
            }
        </script>
        
        <script type="text/javascript">
            function convert(value, rec) {
                //debugger;
                rec.City = value.City;
                rec.StreetAddress = value.StreetAddress;
            }
        </script>
    
    </head>
    <body>
        <ext:ScriptManager ID="ScriptManager1" runat="server" StateProvider="None" />
        
        <ext:Store runat="server" ID="Store1" AutoLoad="true" SerializationMode="Complex">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="ID" Type="Int" />
                        <ext:RecordField Name="FirstName" />
                        <ext:RecordField Name="LastName" />
                        <ext:RecordField Name="Company" />
                        <ext:RecordField Name="Address">
                            <Convert Fn="convert" />
                        </ext:RecordField>
                        <ext:RecordField Name="City" />
                        <ext:RecordField Name="StreetAddress" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        
         <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            Title="Customers" 
            Height="300"
            StoreID="Store1">
            <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:Column Header="ID" DataIndex="ID" />
                <ext:Column Header="FirstName" DataIndex="FirstName"  />
                <ext:Column Header="LastName" DataIndex="LastName" />
                <ext:Column Header="Company" DataIndex="Company"/>            
                <ext:Column Header="City" DataIndex="City"/>            
                <ext:Column Header="Street" DataIndex="StreetAddress"/>            
            </Columns>
            </ColumnModel>
            <LoadMask ShowMask="true" />
        </ext:GridPanel>    
    </body>
    </html>

Similar Threads

  1. [CLOSED] MVC Templates
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 16, 2012, 5:04 PM
  2. Replies: 1
    Last Post: Jun 24, 2011, 7:19 PM
  3. ASP.NET serialization and Store
    By daneel in forum 1.x Help
    Replies: 2
    Last Post: Feb 02, 2010, 6:05 AM
  4. [CLOSED] [1.0] Store wraps GUID value with quotes (serialization)
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 22, 2009, 5:45 PM
  5. Templates column in gridpanel
    By hernanjls in forum 1.x Help
    Replies: 0
    Last Post: Aug 13, 2009, 4:47 PM

Posting Permissions