PDA

View Full Version : ComboBox renderer in EditorGridPanel: valueField/displayField



dmackerman
7 Sep 2011, 11:07 AM
I know this topic has been brought up a couple times, and there are solutions for it, but the issue I'm having is a bit different. Using a renderer, I've gotten the displayField to be shown after a user edits a field in the grid with a Combo as an editor. That works fine. My problem is if I load records into the grid, the ComboBox's display the valueField and not the displayField.

If I do a refresh() on the GridView, it seems to update. My problem now is that I am doing this refresh from inside the renderer, and it's getting called on every row/column that has a ComboBox, which is hanging my app.

Here's my renderer (it's a combination of solutions I've found here and elsewhere)


***.util.Format.comboRenderer = function(combo, grid){
return function(value) {

var combo = this.getEditor();

if (combo.store.getCount() == 0) {
combo.store.on('load', refreshGrid, grid, {

// tried this, still hangs. i've also tried 'single: true'
buffer: 1000
});
}

// just for easy code reading, split out the refresh
function refreshGrid() {
grid.getView().refresh();
}

var idx = combo.store.find(combo.valueField, value);

// I added this line for show all values from loading
if (idx == -1) {
return value;
}

// get the record
var rec = combo.store.getAt(idx);

// return the displayField
return (rec == null ? '' : rec.get(combo.displayField) );

}
}

And how I'm calling the renderer (mainly how I'm getting the grid reference, by calling this)


{
id: 'advertiser',
header: "Advertiser",
name: 'advertiser',
editable: true,
sortable: true,
dataIndex: 'advertiser',
editor: advComboBox, // this is just a standard Combo with a JsonStore
renderer: ***.util.Format.comboRenderer(advComboBox, this)
}

Any other solutions that come to mind?

Ash Sai
16 Sep 2011, 7:44 AM
"My problem is if I load records into the grid, the ComboBox's display the valueField and not the displayField" - Can you share the code which renders the valueField to the comboBox?