[CLOSED] Grid with array of objects

  1. #1

    [CLOSED] Grid with array of objects

    How do I bind an array with custom objects to a gridpanel ? The toolbar shows 1 item, which is correct, but I can't seem to display the values of the object in the grid.
  2. #2

    RE: [CLOSED] Grid with array of objects

    Hi,

    Please see the following sample which demonstrates how to bind array of custom objects
    <%@ Page Language="C#" %>
    
    <%@ 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">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[]
                {
                    new {Company = "3m Co", Price = 71.72, Change = 0.02, PctChange = 0.03, LastChange = "9/1 12:00am"},
                    new {Company = "Alcoa Inc", Price = 29.01,  Change = 0.42,  PctChange = 1.47,  LastChange = "9/1 12:00am"},
                    new {Company = "Altria Group Inc", Price = 83.81,  Change = 0.28,  PctChange = 0.34,  LastChange = "9/1 12:00am"}
                };
    
                this.Store1.DataBind();
            }
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Coolite Toolkit Example - Simple Array Grid</title>   
    
        <script type="text/javascript">
            var template = '{1}';
    
            var change = function(value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value);
            }
    
            var pctChange = function(value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value + '%');
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Company" />
                            <ext:RecordField Name="Price" Type="Float" />
                            <ext:RecordField Name="Change" Type="Float" />
                            <ext:RecordField Name="PctChange" Type="Float" />
                            <ext:RecordField Name="LastChange" Type="Date" DateFormat="n/j h:ia" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel 
                ID="GridPanel1" 
                runat="server" 
                StoreID="Store1" 
                StripeRows="true"
                Title="Array Grid" 
                TrackMouseOver="true"
                Width="600" 
                Height="350"
                AutoExpandColumn="Company">
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="Company" Header="Company" Width="160" Sortable="true" DataIndex="Company" />
                        <ext:Column Header="Price" Width="75" Sortable="true" DataIndex="Price">
                            <Renderer Format="UsMoney" />
                        </ext:Column>
                        <ext:Column Header="Change" Width="75" Sortable="true" DataIndex="Change">
                            <Renderer Fn="change" />
                        </ext:Column>
                        <ext:Column Header="Change" Width="75" Sortable="true" DataIndex="PctChange">
                            <Renderer Fn="pctChange" />
                        </ext:Column>
                        <ext:Column Header="Last Updated" Width="85" Sortable="true" DataIndex="LastChange">
                            <Renderer Fn="Ext.util.Format.dateRenderer('m/d/Y')" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                </SelectionModel>            
            </ext:GridPanel>          
        </form>
    </body>
    </html>
  3. #3

    RE: [CLOSED] Grid with array of objects

    Since I'm using LINQ, the problem is that some of the values in my array are objects again. Can I access them through the following notation ?

    <ext:RecordField Name="Role" Type="String" />
    <ext:Column Header="Price" Width="75" Sortable="true" DataIndex="Role.Name" />



  4. #4

    RE: [CLOSED] Grid with array of objects

    Hi,

    You need set SerializationMode="Complex" for store and use Converter
    Please see*


    https://examples1.ext.net/#/GridPane.../Data_Prepare/





Similar Threads

  1. Saving grid changes with complex objects
    By fquintero in forum 1.x Help
    Replies: 3
    Last Post: Oct 13, 2009, 1:19 PM
  2. Replies: 0
    Last Post: Jun 15, 2009, 8:47 AM
  3. [CLOSED] Grid/Store DataBind to Jagged Object Array
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 03, 2009, 4:49 PM
  4. binding grid to multiple objects
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 25, 2009, 8:38 AM
  5. [CLOSED] array grid
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 21, 2008, 8:46 AM

Posting Permissions