Search code examples
javascriptextjsextjs4

Cell Editing on checkchange event of a checkcolumn


I have been looking for a solution to this in sencha forum as well as on stack overflow. I was unable to get a proper solution to this issue. I want to edit a particular cell of a row in a grid on checkchange event of a check column in that row.

Following is the code-

         var unitStore = Ext.create('Ext.data.Store', {
                            fields: ['phone'], 
                            autoLoad:true ,
                             proxy: {
    type: 'memory',

}
                        });

         var abc=Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
    { 'name': 'Lisa',  "email":"[email protected]",  "phone":"555-111-1224"  },
    { 'name': 'Bart',  "email":"[email protected]",  "phone":"555-222-1234" },
    { 'name': 'Homer', "email":"[email protected]",  "phone":"555-222-1244"  },
    { 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254"  }
]},
proxy: {
    type: 'memory',
    reader: {
        type: 'json',
        root: 'items'
    }
}
   });
   var cellEditing=Ext.create('Ext.grid.plugin.CellEditing', {
      clicksToEdit: 1,
   });
      Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
 plugins: [cellEditing],
store: abc,
columns: [
{xtype:'checkcolumn' ,id:'check',dataIndex:'check', text:'Select' ,listeners:{
        checkchange:function( checkbox, rowIndex, checked, eOpts ){
                 if(checked==true){
                    //var abc=checkbox.up('grid').getStore().getAt(rowIndex).get('name');
                  var x=[{'phone':'2'},{'phone':'3'}];
                  unitStore.loadData(x);
                    //cellEditing.startEditByPosition({row: rowIndex, column: 3});


                 // this.up('grid').getSelectionModel().setCurrentPosition({row:         rowIndex, column: 3});
                   cellEditing.startEdit(rowIndex,3);

                 }


        }
    }},
    { text: 'Name',  dataIndex: 'name' },
    { text: 'Email', dataIndex: 'email', flex: 1 },
    { text: 'Phone', dataIndex: 'phone',editor:{xtype:'combo',store:unitStore,
     queryMode:'local',displayField: 'phone',
valueField: 'phone',selectOnFocus:true,triggerAction: 'all',
     } },

],
height: 200,
width: 400,
renderTo: Ext.getBody()
   }); 

Solution

  • Use Ext.defer to delay before calling startEdit function. Modified your sample in this fiddle: https://fiddle.sencha.com/#fiddle/9lm