【问题标题】:ComboBox in editable grid: can't see the value可编辑网格中的组合框:看不到值
【发布时间】:2012-04-10 03:42:14
【问题描述】:

我有一个使用商店的可编辑网格。我想在其中一个字段中插入一个组合框。 这是我的网格商店:

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

还有一个仅适用于组合框的商店,其中包含“wid”和“名称”字段。 在我的专栏模型中:

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

还有组合本身:

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

加载网格时,其字段“Worker”为空(没关系),但其中没有组合框。当我开始编辑它时,我看到了所有列表。编辑后,“id”被保存到商店,但“名称”不显示,组合框也不显示。 我做错了什么?

【问题讨论】:

    标签: extjs


    【解决方案1】:

    这有帮助:

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

    【讨论】:

    • 我将如何在 ExtJS 设计器中实现它?
    • 我不使用 ExtJS 设计器,但我认为您可以将它放在脚本的头部。并在网格字段中:editor: yourCmb, renderer: Ext.util.Format.comboRenderer(yourCmb)
    【解决方案2】:

    如果您在组合框中启用过滤('queryMode = local'),请记住,您输入的每个字母都会应用于存储。因此,函数 findRecord 将无法找到被过滤掉的显示名称。这将影响您在同一网格中的其他行,因为在您完成编辑后,整个网格视图将刷新。

    为确保在循环开始时不会丢失任何记录,请在尝试查找记录之前从组合框存储中删除过滤器。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      相关资源
      最近更新 更多