ExtJS如何在网格面板中构建链接组合框

ExtJS how to build linkage comboboxes in Grid panel

本文关键字:构建 链接 组合 网格 ExtJS      更新时间:2023-09-26

我是ExtJS的新手,我正在制作一个地址簿,管理员可以通过从两个组合框中选择列出的州和城市来编辑用户的地址。

我需要在网格面板中建立一些链接组合框,以便在第一个下拉列表中选择一个状态后,亲属城市将自动在第二个下拉列表中列出。

如果它只是一个简单的面板,我可以在state被选中后使用以下代码更新cityStore:

        {                               
            xtype:"combo",                                                                                   
            name:'state',  
            id:'state',  
            displayField:'name',  
            valueField:'id',  
            store:storeState,  
            triggerAction:'all',  
            queryMode:'local',  
            selecOnFocus:true,  
            forceSelection:true,  
            allowBlank:false,  
            editable:true,
            //using select listener for updating city store  
            listeners:{  
                select:function(combo,record,index){  
                    try{  
                        var city = Ext.getCmp('city');  
                        city.clearValue();  
                        city.store.load(  
                             {  
                                 params:{  
                                     paramId:combo.getValue()  
                                 }  
                             }     
                        );  
                    }catch(ex){  
                        alert("Failed to load data");  
                    }  
                }  
                }  
        },

然而,在GridPanel中,如果我以相同的方式更新cityStore,整个列将改变。是否有无论如何,只解决在网格面板的同一行列?谢谢!

您需要使用validateedit &beforeedit事件的网格更新城市存储。

listeners: {
        validateedit: {  // to check if state value is changed & clearing city value
                fn: function(event,editor){ 
                    switch (editor.field) {
            case 'state':
                 if(editor.value!=editor.record.getData().state)
                     editor.record.set('city',null);
                break;
             }
        return true;
        }
        },
        beforeedit: { // to update the city store based the state value of corresponding row
                fn: function(event,editor){                   
        switch (editor.field) {
            case 'city':
                  var cityStore = Ext.data.StoreManager.lookup('cityStore');
                 cityStore.load({  
                                  params:{  
                                         paramId:editor.value 
                                         }  
                                   });  
                 break;
                }
         return true;
         }
        }
       }

这里是一个工作示例,我使用两个本地存储状态&的城市。当使用在同一行中给定的state值编辑城市存储时,过滤城市存储。有三个状态A,B,C和1-5,6-10 &分别是11-15个城市。

您只需要在每次用户单击City编辑器时使用来自State的参数重新加载Cities存储。在组合框的beforequery事件中执行。

{
    //this is your Cities combo
    xtype: 'combo',
    valueField: 'foo',
    displayField: 'bar',
    queryMode: 'remote',
    queryCaching: false, //don't forget to disable query caching        
    bind: {
        store: '{cities}',   
    },
    listeners: {
        beforequery: function(queryPlan) {
            //get param from your States store
            queryPlan.combo.getStore();
            //then load this store
        }
    }
}