[CLOSED] Looping through a gridpanel

  1. #1

    [CLOSED] Looping through a gridpanel

    Hi,


    Can u give me a sample code on how i can loop through a grid panel. The Scenario is the i have created a calculation sheet using grid panel, user inputs some calculations in the grid panel and then press the calculate button. I searched on the web but every one is saying to loop through the store, but that doesn't serve the purpose as user is giving input at runtime.

    Thanks In Advance
    Last edited by Daniil; Feb 19, 2013 at 3:33 AM. Reason: [CLOSED]
  2. #2
    Hello!

    They are actually are right because Grid just represent all data while all data stored in store.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = this.Data;
                this.Store1.DataBind();
            }
        }
    
        private object[] Data
        {
            get
            {
                return new object[]
                {
                    new object[] { "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" },
                    new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
                    new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
                    new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" },
                    new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, "9/1 12:00am" },
                    new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, "9/1 12:00am" },
                    new object[] { "Boeing Co.", 75.43, 0.53, 0.71, "9/1 12:00am" }
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    
        <style>
            .x-grid-row-over .x-grid-cell-inner {
                font-weight : bold;
            }
        </style>
    
        <script>
            var template = '<span style="color:{0};">{1}</span>';
    
            var change = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value);
            };
    
            var pctChange = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        
        <ext:Button runat="server" Text="Get total price of all companies">
            <Listeners>
                <Click Handler="
                var s = 0; 
                App.GridPanel1.getStore().getRecordsValues().forEach(function(item) { 
                    s += item.price 
                });
                Ext.Msg.alert('Total price for all companies', 'Total = ' + Ext.util.Format.usMoney(s));"></Click>
            </Listeners>
        </ext:Button>
        <ext:GridPanel 
            ID="GridPanel1"
            runat="server" 
            Title="Array Grid" 
            Width="600" 
            Height="350">
            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="company" />
                                <ext:ModelField Name="price" Type="Float" />
                                <ext:ModelField Name="change" Type="Float" />
                                <ext:ModelField Name="pctChange" Type="Float" />
                                <ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel>
                <Columns>
                    <ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
                    <ext:Column runat="server" Text="Price" DataIndex="price">                  
                        <Editor>
                            <ext:NumberField runat="server" AllowBlank="false" MinValue="0" MaxValue="100000">
                            </ext:NumberField>
                        </Editor>
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                    <ext:Column runat="server" Text="Change" DataIndex="change">
                        <Renderer Fn="change" />
                    </ext:Column>
                    <ext:Column runat="server" Text="Change" DataIndex="pctChange">
                        <Renderer Fn="pctChange" />
                    </ext:Column>
                    <ext:DateColumn runat="server" Text="Last Updated" DataIndex="lastChange" />
                </Columns>            
            </ColumnModel>       
            <SelectionModel>
                <ext:RowSelectionModel runat="server" />
            </SelectionModel>
            <Plugins>
                <ext:CellEditing runat="server"></ext:CellEditing>
            </Plugins>
        </ext:GridPanel>
    </body>
    </html>

Similar Threads

  1. Infinite looping with search
    By stonegate in forum 2.x Help
    Replies: 1
    Last Post: Oct 29, 2012, 12:28 PM
  2. [CLOSED] [1.0] Looping through FormPanel fields
    By danielg in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 08, 2010, 7:42 AM

Posting Permissions