【问题标题】:How to filter store in combobox of editorgrid based on record's value?如何根据记录的值过滤编辑器网格组合框中的存储?
【发布时间】:2015-08-01 18:58:38
【问题描述】:

我有一个网格,其中有一列用于组合框。我需要根据下面的记录过滤掉组合框的值:

 id  |   name    |      options
======================================
1    |  string   |  combobox(1,2,3)
2    |  string   |  combobox(1,2,3,4,5)
3    |  string   |  combobox(1,2,3)
1    |  string   |  combobox(1,2,3)

所以最终我需要基于id 列的选项值。以下是我的 extjs 网格列配置。

columns: [{
                header: 'id',
                dataIndex: 'id',
                id: 'id',
                hidden: true
            },{
                header: 'Name',
                dataIndex: 'name',
                id: 'name',
                menuDisabled: true,
                flex : 1 
            },{
                header: 'options',
                dataIndex: 'options',
                id: 'options',
                menuDisabled: true,
                flex : 1,
                editor : {
                    xtype : 'combo',
                    store: optionStore,
                    valueField: 'id',
                    displayField: 'name',
                    triggerAction: 'all',
                    mode : 'local',
                    disabled: true,
                    listners: {
                        expand: this.filterFunc(this)
                    }
               },
               renderer: this.columnRenderer
            }]

如何在没有 ExtJS 编辑器网格中的不同行的情况下过滤存储。

P.S - 我使用的是 extjs 3.4 版本

【问题讨论】:

    标签: extjs combobox grid extjs3


    【解决方案1】:

    你可以使用渲染器,它应该是这样的:

    renderer: function( value, metaData, record, rowIndex, colIndex, store ) {
        value.store.filter( [
            {
                property: 'filteredProperty',
                value: record.get('id')
            }
        ] );
    }
    

    【讨论】:

    • 谢谢,但它对我不起作用,因为我使用特殊的渲染器在下拉列表中显示值。
    • 渲染器看起来怎么样?难道不能用那个渲染器来过滤属性吗?
    • 不@MarthyM,改变渲染器有点复杂。尽管您的解决方案完美无缺,但我仍在发布解决问题的方法。
    【解决方案2】:

    我在下面的列配置中使用了侦听器expand,它在扩展组合框列表时过滤商店。

    {
        header: 'options',
        dataIndex: 'options',
        id: 'options',
        menuDisabled: true,
        flex : 1,
        editor : {
            xtype : 'combo',
            store: optionStore,
            valueField: 'id',
            displayField: 'name',
            triggerAction: 'all',
            mode : 'local',
            disabled: true,
            listeners: {
                expand : function(combo){
                    var id = Ext.getCmp('grid').getSelectionModel().selection.record.data.id;
                    combo.store.filter('attributeId',attributeId);
                }
            }
       },
       renderer: this.columnRenderer
    }
    

    【讨论】:

    • 很好的解决方案。不过,我个人会使用afterrender 听众。如果您使用expand,它可能会在您展开之前显示一个不在过滤列表中的默认值。
    • 感谢您的关注,但不存在这样的价值,因为我已经在数据库中设置了约束。 :)
    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多