views:

647

answers:

1

Hi,

I have an Editor Grid where if a specific cell is in focus (is being edited), a window containing a tree panel pops up allowing the user to choose a node from the treepanel as the new value of the cell. This way, the user isn't actually editing the cell in question, but is using the window to choose the new value. However, I am having difficulties setting the value of the cell in question programmatically.

Below is the code I use to set the grid up, including the column model that chooses what editor to use for a cell depending on the value type:

var editorCM = new Ext.grid.ColumnModel({
  //config
  ,editors : {
    //rest of editors
    'id' : new Ext.grid.GridEditor(new Ext.form.TextField({readOnly : true}))
  }
  ,getCellEditor : function(col, row) {
    //choose editor depending on the type value of a cell
  }
})

var editorGrid = new Ext.grid.EditorGridPanel({
  //rest of config
  ,cm : editorCM
})

Below is my code to change the cell's value once the user chooses from the treepanel.

function submitNode(newValue) {
  var temp = editorGrid.GetSelectionModel().getSelectedCell(); //returns array containing column and row position of selected cell, which value we want to change.

  //temp[1] = column index, temp[0] = row index
  //Gets the cell editor at specific position and sets new value for that cell
  editorGrid.getColumnModel().getCellEditor(temp[1], temp[0]).setValue(newValue);
}

I've also tried a few other ways (all including setValue(newValue)), but have come up empty handed. I've looked through the API and the ExtJS forums for any clue but have also come up empty handed.

A: 

I've not worked with the editor grid, so I'm hanging it out there a bit.

looking at this for reference: http://www.extjs.com/deploy/dev/examples/grid/edit-grid.js

it seems the way they did it (for adding) was to update the store directly and if you could identify the store record you could surely update it directly.

look at the handler for addPlant:

 handler : function(){
            // access the Record constructor through the grid's store
            var Plant = grid.getStore().recordType;
            var p = new Plant({
                common: 'New Plant 1',
                light: 'Mostly Shade',
                price: 0,
                availDate: (new Date()).clearTime(),
                indoor: false
            });
            grid.stopEditing();
            store.insert(0, p);
            grid.startEditing(0, 0);
        }

failing that, I'd be interested to see what happens when you make your field not read only:

  ,editors : {
//rest of editors
'id' : new Ext.grid.GridEditor(new Ext.form.TextField({readOnly : false}))  }

just a couple of thoughts.

ruzz