[CLOSED] GridPanel numberfield problem

  1. #1

    [CLOSED] GridPanel numberfield problem

    Hi,

    In a page, i need to add columns to a grid panel dynamically in code behind. When the column is a numbercolumn and i bind decimal values to it, the column shows 0,00 as value instead of real value. (I'm using Turkish number format.) Ext.net version is 2.4.

    Here is the code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicGridProblem.aspx.cs" Inherits="DynamicGridProblem" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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></title>
        <script runat="server">
            
            object[] Names = new object[] { "Name1", "Name2" };
            object[] Heights = new object[] { 1.75, 1.85 };
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    if (X.IsAjaxRequest)
                    {
                        this.MyStore.AddField(new ModelField("Height", ModelFieldType.Float));
                    }
                    else
                    {
                        MyStore.Model[0].Fields.Add(new ModelField("Height", ModelFieldType.Float));
                    }
                    NumberField numberField = new NumberField();
                    numberField.ID = "txtHeight";
                    numberField.KeyNavEnabled = false;
                    numberField.HideTrigger = true;
    
                    NumberColumn numColumn = new NumberColumn();
                    numColumn.DataIndex = "Height";
                    numColumn.Text = "Height";
                    numColumn.ID = "colHeight";
                    numColumn.Flex = 1;
                    numColumn.Editor.Add(numberField);
                    MyGrid.ColumnModel.Columns.Add(numColumn);
                    MyStore.RebuildMeta();
                }
            }
    
            protected void RetrieveData(object sender, DirectEventArgs e)
            {
                System.Data.DataTable myDataTable = new System.Data.DataTable();
                myDataTable.Columns.Add("Name");
                myDataTable.Columns.Add("Height", typeof(Decimal));
    
                for (int i = 0; i < 2; i++)
                {
                    object[] item = new object[2];
                    item[0] = Names[i];
                    item[1] = Heights[i];
    
                    myDataTable.Rows.Add(item);
                }
    
                MyStore.DataSource = myDataTable;
                MyStore.DataBind();
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <form id="form1" runat="server">
        <ext:GridPanel ID="MyGrid" runat="server" MinHeight="100" MarginSpec="5 5 5 5" Width="200">
            <Store>
                <ext:Store ID="MyStore" runat="server">
                    <Model>
                        <ext:Model ID="MyModel" runat="server">
                            <Fields>
                                <ext:ModelField Name="Name" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel ID="MyColumnModel" runat="server">
                <Columns>
                    <ext:Column ID="colName" runat="server" DataIndex="Name" Text="Name" Flex="1" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="MyRowSelectionModel" runat="server" />
            </SelectionModel>
        </ext:GridPanel>
        <ext:Button ID="MyButton" runat="server" Text="Retrieve Data" MarginSpec="5 5 5 5">
            <DirectEvents>
                <Click OnEvent="RetrieveData" />
            </DirectEvents>
        </ext:Button>
        </form>
    </body>
    </html>
    Any help would be much appreciated.
    Thanks.
    Last edited by Daniil; Jun 24, 2014 at 2:15 PM. Reason: [CLOSED]
  2. #2
    Hi @metci,

    By the time this is executed
    MyStore.DataSource = myDataTable;
    all the required ModelFields should be in the Model's Fields.

    Please note that "IsPostBack" is true during a DirectEvent. So, your code in Page_Load is not executed on RetrieveData.

    If a Model and a ColumnModel depends on the structure of loaded data, then I would recommend to follow this example.
    https://examples2.ext.net/#/GridPane...n/Meta_config/

Similar Threads

  1. [CLOSED] [1.7] Problem with NumberField
    By John_Writers in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 31, 2013, 3:15 PM
  2. [CLOSED] Getting NumberField problem
    By Bert76 in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jul 16, 2013, 2:50 PM
  3. [CLOSED] NumberField problem step
    By JCarlosF in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 18, 2013, 4:47 AM
  4. NumberField Problem
    By littletran in forum 1.x Help
    Replies: 2
    Last Post: Mar 02, 2013, 12:37 AM
  5. [CLOSED] Numberfield Problem
    By webppl in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 09, 2011, 9:09 AM

Posting Permissions