PDA

View Full Version : EditorGrid, Comboboxes and change event



johnmcteague
14 Dec 2012, 1:44 AM
I have an editor grid with combo box using data loaded from a json store. In my use case, I want to add a change event to the combo box so that when the value is changed, I automatically initiate a remote call to update the value. I also allow the user to type in a new value if its not already in the list. To do that I also need the id value from my row.

The code below is a snippet from my application. To execute my ajax request in the changeFolder function I need the id from the current record that I am editing but that is not available to me in the change event handler.

Does anyone have a good suggestion?



var myStore= new Ext.data.JsonStore({
fields: [
{name: 'id'},
{name: 'name'},
{name: 'folder'}

],
....
});

var changeFolder = function(combo, oldVal, newVal){
//How do i get the records id value here to use in a remote ajax request along with newVal?
}

var grid = new Ext.grid.EditorGridPanel({
.....
cm : new Ext.grid.ColumnModel( {
columns: [

{header:"Name", width:200},
{

header:"Folder",


renderer: function(){ // display the actual value }, ]
editor:{


store: myStore,


xtype: 'combo',
displayField:'folder',
valueField: 'folder',
mode: 'local',
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
editable:true,
loadingText: 'Loading folders...',
listEmptyText : 'Type a folder...',
listeners: {
change: changeFolder,
}


}}]


...
})
....
});

johnmcteague
14 Dec 2012, 1:50 AM
My initial thought was to attach the current records id to the combo box in the renderer, but since it is a single instance of the combo shared by all rows, that idea went out the window quickly,

johnmcteague
14 Dec 2012, 2:18 AM
My other attempt at solving this was to do the following in the change handler:



return Ext.getCmp('myGrid').getSelectionModel().selection.record.id;


This works when the user uses the enter key to confirm the change or actually clicks on an item in the list.

It does not work if the user types into the combo and clicks somewhere else on the screen. If the place where the user clicks is a different row, the id I get is for that new row, not the row that was edited.