Cell Editing startEdit problem

  1. #1

    Cell Editing startEdit problem

    I have a button to add a new record into the grid. When I click the add button I want to add a record into the store and then start editing the record in the grid...

           function doAdd() {
                var rec = App.Store1.add({company: 'New Company'})[0];
                App.CellEditing1.startEdit(rec, App.GridPanel1.columns[0]);
            }
    This works fine if there is no IDProperty set on the Model....it has the desired effect (record added then first column of newly added row has the editor active).

    However if you add an IDProperty to the model. It sets the editor but quickly goes back to the previously selected item.

    Working Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Store1.DataSource = Data();
            Store1.DataBind();
        }
    
        [DirectMethod]
        public object[] Data()
        {
            
                return new object[]
                {
                    new object[] { 1, "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" },
                    new object[] { 2, "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
                    new object[] { 3,"Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
                    new object[] { 4,"American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" },
                    new object[] { 5, "American International Group, Inc.", 64.13, 0.31, 0.49, "9/1 12:00am" }
                 
                };
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>Simple Array Grid - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />    
    
        <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 ID="ResourceManager1" runat="server" Theme="Neptune" ScriptMode="Debug"/>
        
        <h1>Simple Array Grid</h1>
        
        <ext:Button runat="server" Text="Show and Select">
            <Listeners>
                <Click Handler="doAdd();" />
            </Listeners>
        </ext:Button>
    
        
        <script type="text/javascript">
            function doAdd() {
                var rec = App.Store1.add({company: 'New Company'})[0];
                App.CellEditing1.startEdit(rec, App.GridPanel1.columns[0]);
            }
        </script>
        
            
            
        <ext:GridPanel 
            ID="GridPanel1"
            runat="server" 
            Title="Array Grid" 
            Flex="1"
            Width="600">
            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="companyId" Type="Int" />
                                <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 ID="Column1" runat="server" Text="Company" DataIndex="company" Flex="1">
                        <Editor>
                            <ext:TextField runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column ID="Column2" runat="server" Text="Price" DataIndex="price">                  
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                    <ext:Column ID="Column3" runat="server" Text="Change" DataIndex="change">
                        <Renderer Fn="change" />
                    </ext:Column>
                    <ext:Column ID="Column4" runat="server" Text="Change" DataIndex="pctChange">
                        <Renderer Fn="pctChange" />
                    </ext:Column>
                    <ext:DateColumn ID="DateColumn1" runat="server" Text="Last Updated" DataIndex="lastChange" />
                </Columns>            
            </ColumnModel>       
            <Plugins>
                <ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1" />
            </Plugins>
            <BottomBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="Button1" runat="server" Text="Print" Icon="Printer" Handler="this.up('grid').print();" />
                    </Items>
                </ext:Toolbar>
            </BottomBar>
            
    
        </ext:GridPanel>
        
    </body>
    </html>
    To make it not work change the Model declaration to this

         <ext:Model ID="Model1" runat="server" IDProperty="companyId">
  2. #2
    Ok I can see that the issue is that I need to specify a value for the IDProperty field ie. give it a unique companyId.....I gather the fact that it is assigning 0 to the companyId is causing it an issue?

    Not sure how I get around this? I have a store that is not autoSynced and I submit all by a save button so I dont have an Id field to give it. Server side it is expecting a 0 in there for phantom records so I can't really change it?

Similar Threads

  1. Replies: 0
    Last Post: May 29, 2013, 7:12 AM
  2. [CLOSED] Disabling cell editing based on cell value in Ext.Net 2.1
    By bayoglu in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 30, 2013, 5:35 PM
  3. [CLOSED] Cell editing with complex editor
    By Leonid_Veriga in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 21, 2012, 5:21 PM
  4. Replies: 4
    Last Post: Jul 10, 2012, 5:35 PM
  5. [CLOSED] Editing cell of gridPanel
    By supera in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: May 23, 2012, 12:47 PM

Posting Permissions