ComboBox in editable grid: can't see the value

被刻印的时光 ゝ 提交于 2019-12-11 05:29:57

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/5133453/combobox-in-editable-grid-cant-see-the-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!