Search code examples
extjsextjs4

Extjs 4.0.7-Access editor field on grid load


I have a grid which has a column with editor defined like below.

   this.accrualGrid = new Ext.grid.GridPanel({
        store: store,
        id:'accrualGrid_add',
        plugins :[this.cellEditing],
        columns: [

            {header: 'Milestone Description', width: 340, dataIndex: 'Description',

                getEditor: function(record) {
                    if(Ext.getCmp('accrualGrid_add').store.indexOf(record)==0)
                    {
                        return Ext.create('Ext.grid.CellEditor', {

                            field: Ext.create('Ext.form.field.Text', {

                                id:'MDesc_Add',
                                validator:function(val){
                                    if(val=="")
                                      return false;
                                    else
                                      return true;
                                },
                            })
                        });

                   }

                }
            }]

Everytime the grid the loaded, I am not able the access the textfield inside editor until we click on that cell.

Ext.getCmp('MDesc_Add') gives undefined value.

After I click on that cell, It gives me the textfield object.

How can I access the textfield object just on grid load or set data of grid??


Solution

  • This is because you instantiate the field inside the getEditor method, which is called only when the editor is needed (when it should be displayed).

    If you want the field to be always available, you should instantiate it before you instantiate the grid:

    var editorField = Ext.create('Ext.form.field.Text', {
            id:'MDesc_Add',
            validator:function(val){
            if(val=="") return false;
            else return true;
        });
    this.accrualGrid = new Ext.grid.GridPanel({
        ...
                  return Ext.create('Ext.grid.CellEditor', {
                      field: editorField
                  });
        ...
    });