Search code examples
comboboxextjs4

Extjs4 combobox displayValue in grid


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'
    }
},...]

Solution

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'
    });

And all is fine, but I can't edit it. What is the problem?

Sorry for my English.


Solution

  • 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; 
                    }
                }