[CLOSED] Insert Grid Record - Edit First Cell?

  1. #1

    [CLOSED] Insert Grid Record - Edit First Cell?

    I've seen posts like http://forums.ext.net/showthread.php...cord-gridpanel whereby the row is focussed, but is it possible to actually have the grid go into edit mode (ie: as though I'd double-clicked on the cell)? Or, is this what is meant to happen?

    The code I've tried (in a function) is:

             
                insertGridRecord: function (grid, record, defaultEditCol, showErrors) {
                        var count = grid.getStore().getTotalCount();
                        grid.insertRecord(count, (record != null) ? record : {}, false);
                        grid.startEditing(count + 1, defaultEditCol || 0);
                        grid.selModel.selectRow(0);
                }
    .. this does everything I expect, except the row never goes into edit mode; it is just highlighted. Am I doing something wrong? I'm calling the code thus:

    <ext:Button ID="btnNew" runat="server" Text="New" Icon="Add">
        <Listeners>
            <Click Handler="SaveAndInvest.insertGridRecord(#{gridChequeDiaries}, { ReconciledStatus:'Draft' }, 0);" />
        </Listeners>
    </ext:Button>
    Many thanks.
    Last edited by Daniil; May 17, 2011 at 1:59 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please see the example.

    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) {
                var index = grid.addRecord({id : 'someId' + i++});
                grid.selModel.selectRow(index);
                grid.startEditing(index, 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>
            <SelectionModel>
                <ext:RowSelectionModel runat="server" />
            </SelectionModel>
        </ext:GridPanel>
        <ext:Button runat="server" Text="Add">
            <Listeners>
                <Click Handler="add(GridPanel1);" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Thank you, it works now. Can you tell me what the last two parameters in addRecord do?

    addRecord(values, commit, clearFilter)
    I know values will be a record object, but commit I'm not sure about.

    Cheers.
  4. #4
    Internally, the grid's .addRecord() calls the store's .insertRecord(). Here is its sources:
    insertRecord : function (rowIndex, values, asSorted, commit, clearFilter) {
        if (clearFilter !== false) {
            this.clearFilter(false);
        }
        values = values || {};
    
        var f = this.recordType.prototype.fields, 
            dv = {},
            i = 0;
    
        for (i; i < f.length; i++) {
            dv[f.items[i].name] = f.items[i].defaultValue;
    
            if (!Ext.isEmpty(values[f.items[i].name])) {
                values[f.items[i].name] = f.items[i].convert(values[f.items[i].name], values);
            }
        }
    
        var record = new this.recordType(dv, values[this.metaId()]), v;
    
        record.newRecord = true;        
    
        record.beginEdit();
        
        for (v in values) {
            record.set(v, values[v]);
        }
    
        if (!Ext.isEmpty(this.metaId())) {
            record.set(this.metaId(), record.id);
        }
    
        record.endEdit();
        
        if (this.groupField && !asSorted) {
            this.totalLength = Math.max(1, this.data.length + 1);
            this.add(record);
            this.fireEvent("load", this, record, { add: true });
    
            this.suspendEvents();
            this.applyGrouping(true);
            this.resumeEvents();
            this.fireEvent("datachanged", this);
        } else {
            if (!asSorted) {
                this.insert(rowIndex, record);
            } else {
                this.addSorted(record);
            }
        }
    
        if (commit) {
            record.phantom = false;
            record.commit();            
        }
        
        if (!Ext.isDefined(this.writer) && this.modified.indexOf(record) === -1) {
            this.modified.push(record);
        }
    
        return record;
    }
    I believe now you know what these arguments stand for:)

Similar Threads

  1. Replies: 4
    Last Post: Oct 07, 2011, 10:49 AM
  2. [CLOSED] insert record
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 12, 2010, 4:08 PM
  3. [CLOSED] I can not edit inserted record in a grid.
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 03, 2010, 8:20 PM
  4. [CLOSED] Insert Record into grid
    By sharif in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 08, 2010, 2:16 PM
  5. Replies: 0
    Last Post: Sep 17, 2009, 8:04 AM

Tags for this Thread

Posting Permissions