Please, help.
I want to show my displayValue in the Grid.
I found the solution here, but I can't understand how use it. My code:
columns:[...,{
    header: 'Product',
    id: 'combo',
    locked: true,
    dataIndex: 'prod_id',
    editor: {
        xtype: 'combobox',
        store: new Ext.data.Store({
            fields: ['value','display'],
            data: prod_list
    }),
    displayField: 'display',
    valueField: 'value'
    }
},...]
Ext.util.Format.comboRenderer = function(combo){
    return function(value){
    var record = combo.findRecord(combo.valueField || combo.displayField, value);
        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
    }
}
{
    header: 'Товар',
    id: 'combo',
    locked: true,
    dataIndex: 'prod_id',
    editor: MyEditor,
    renderer: Ext.util.Format.comboRenderer(MyEditor)
}
I tried to define editor outside of the column array.
    var MyEditor = new Ext.form.field.ComboBox({
        store: new Ext.data.Store({
            fields: ['value','display'],
            data: prod_list
        }),
        displayField: 'display',
        valueField: 'value'
    });
Sorry for my English.
var myStore = new Ext.data.Store({
    fields: ['value','display'],
    data: prod_list
});
...
            editor: {
                xtype: 'combobox',
                store: myStore,
                displayField: 'display',
                valueField: 'value'
            },
            renderer: function(val){
                index = myStore.findExact('value',val); 
                if (index != -1){
                    rs = myStore.getAt(index).data; 
                    return rs.display; 
                }
            }
You are missing a celleditor plugin.
It is best if you define the renderer as a reusable object so that you can globally control the behavior of your combo columns.
Since you are using ExtJS4, I added an alternative way to show the displayField of the combo editor in a cell, without having to define the editor outside of the scope of a column.
First define the renderer:
Ext.ns("Ext.ux.util");
Ext.ux.util.ComboRenderer = function(val, metaData){
    var combo = metaData.column.getEditor();
    if(val && combo && combo.store && combo.displayField){
        var index = combo.store.findExact(combo.valueField, val);
        if(index >= 0){
            return combo.store.getAt(index).get(combo.displayField);
        }
    }
    return val;
};
Then give your grid a cellediting plugin:
  plugins: [
    {
      ptype: 'cellediting',
      clicksToEdit: 1
    }
  ]
And finally, assign the ComboRenderer to your column's renderer property like this:
{
  header: 'Product',
  dataIndex: 'prod_id',
  renderer: Ext.ux.util.ComboRenderer,
  editor: {
    xtype: 'combo',
    store: new Ext.data.Store({
        fields: ['value','display'],
        data: prod_list
    })
  }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With