Extjs4 combobox displayValue in grid

后端 未结 2 544
时光取名叫无心
时光取名叫无心 2021-01-03 01:37

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:[...,{         


        
2条回答
  •  再見小時候
    2021-01-03 02:34

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

提交回复
热议问题