开发者

ComboBox in editable grid: can't see the value

开发者 https://www.devze.com 2023-02-14 05:10 出处:网络
I have an editable grid that uses a store. I want to insert a combobox in one of the fields. This is my store for the grid:

I have an editable grid that uses a store. I want to insert a combobox in one of the fields. This is my store for the grid:

new Ext.data.Store({  ....
 proxy: new Ext.data.HttpProxy......
 reader: new Ext.data.JsonReader({   
            root: 'rows',
            fields: [..... {name:'wid', mapping: 'wid'},

There is another store for combobox only, which has 'wid' and 'name' fields. In my column model:

 header: 'Worker',
    dataIndex: 'wid',
    editor: new Ext.grid.GridEditor(workerCmb),
    renderer:function(value, p, record){
    return record.data['name'];}

And the combo itself:

  valueField: 'wid',
            displayField: 'name',

When the grid is loaded its field "Worker" is empty (it is ok), but there is no combobox in it. When I开发者_运维问答 start editing it, I see all the list. After editing the 'id' is saved to the store, but the 'name' is not shown, neither is the combobox. What am I doing wrong?


this helped:

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


If you enable filtering ('queryMode = local') in your combobox keep in mind that every letter you put in is applied to the store. Therefore, the function findRecord will fail to find display names for the ones that are filtered out. This will affect the other lines you have in the same grid since after you finish editing the whole grid view will refresh.

To make sure you don't loose any records when the loop kicks in, remove the filters from the combobox store before you try to find the record.

Ext.util.Format.comboRenderer = function(combo){
    return function(value){
        combo.store.clearFilter(); // -> addition
        var record = combo.findRecord(combo.valueField || combo.displayField, value);
        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号