[CLOSED] focus on first cell in new record gridpanel

  1. #1

    [CLOSED] focus on first cell in new record gridpanel

    hi,

    I add new record in gridpanel. I want to focus in first cell

    I tried this code but not work

    var addRecordInGrid = function (id) {
            
                grid.insertRecord(0, {id : controlRecordPropertyId()}); 
                grid.startEditing(0, 0);
                grid.selModel.selectRow(0);
                grid.getView().focusCell(0,3);
            }
    Last edited by Daniil; Feb 25, 2011 at 12:56 PM. Reason: [CLOSED]
  2. #2
    Hi,

    .startEditing() should be enough - it works fine in the example below.

    So, please provide a full sample.

    Example
    <%@ 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)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test11", "test12", "test13" },
                    new object[] { "test12", "test22", "test23" },
                    new object[] { "test13", "test32", "test33" }
                };
                store.DataBind();
            }
        }
    </script>
    
    <!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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var i = 0;
        
            var add = function (grid) {
                grid.insertRecord(0, {id : 'someId' + i++});
                grid.startEditing(0, 0);
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test1" />
                                <ext:RecordField Name="test2" />
                                <ext:RecordField Name="test3" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test1" DataIndex="test1">
                        <Editor>
                            <ext:TextField runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="Test2" DataIndex="test2">
                        <Editor>
                            <ext:TextField runat="server" />
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="Test3" DataIndex="test3">
                        <Editor>
                            <ext:TextField runat="server" />
                        </Editor>
                    </ext:Column>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        <ext:Button runat="server" Text="Add">
            <Listeners>
                <Click Handler="add(GridPanel1);" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    yes this is works :) ok why this code didn't work :confused: i want to teach reason this error :)
  4. #4
    grid.insertRecord(0, {id : controlRecordPropertyId()}); 
    grid.startEditing(0, 0);
    grid.selModel.selectRow(0);
    grid.getView().focusCell(0,3);
    Well, generally speaking, this code doesn't make sense.

    Also don't call .focusCell() when grid is in editing mode, it's wrong.

    If you need to focus a cell please call .stopEditing() before to ensure that grid is not under editing.
    Last edited by Daniil; Feb 25, 2011 at 11:53 AM.
  5. #5
    thank you daniil,:o
  6. #6
    Quote Originally Posted by Daniil View Post
    grid.insertRecord(0, {id : controlRecordPropertyId()}); 
    grid.startEditing(0, 0);
    grid.selModel.selectRow(0);
    grid.getView().focusCell(0,3);
    Well, generally speaking, this code doesn't make sense.

    Also don't call .focusCell() when grid is in editing mode, it's wrong.

    If you need to focus a cell please call .stopEditing() before to ensure that grid is not under editing.

    I tried this to get the cell I wanted to focus, but then using the arrow keys to navigate doesn't seem to work...any ideas?
  7. #7
    Hi @rthiney,

    Unfortunately, no idea. Please provide a sample to reproduce.

Similar Threads

  1. GridPanel cell focus
    By Dominik in forum 1.x Help
    Replies: 12
    Last Post: Mar 02, 2012, 11:21 AM
  2. [CLOSED] Have cell, want to trigger editor and give focus...
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 21, 2011, 6:01 PM
  3. Replies: 0
    Last Post: Apr 27, 2010, 9:09 PM
  4. Replies: 5
    Last Post: Aug 27, 2009, 7:01 AM
  5. GP - Validate Edit Keep Cell Focus
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Jun 05, 2009, 8:14 AM

Posting Permissions