ExtJS动态过滤ComboBox

ExtJS filter ComboBox dynamically

本文关键字:ComboBox 过滤 动态 ExtJS      更新时间:2023-09-26

我有一个包含多个组合框的属性网格,我想根据前一个框中选择的内容过滤其中一个框中的值。

我的代码是这样的:

var tempPropGrid = me.getView().add(
    {
        xtype:'propertygrid',
        width: 80,
        header: false,
        title: 'prop grid',
        //for some reason the headers are not hiding, we may need to deal with this using CSS
        //hideHeaders: true,
        enableColumnResize: false,
        sortableColumns: false,
        nameColumnWidth: 1,
        source: record.data,
        sourceConfig: {
            teamName: {
                editor: Ext.create('Ext.form.ComboBox', {
                    store: teams,
                    queryMode: 'local',
                    displayField: 'teamName',
                    valueField: 'teamName'
                }),
                displayName: 'Team'
            },
            leadDev : {
                editor: Ext.create('Ext.form.ComboBox', {
                    store: teamMembers.filter('teamName', teamName.value), // this probably won't work but you get the idea
                    queryMode: 'local',
                    displayField: 'personName',
                    valueField: 'personName'
                }),
                displayName: 'Lead Dev'
            },

和我的JSON对象看起来像这样:

{
                    "periodName": "Week1",
                    "teamName": "tango",
                    "roleName": "SWE III",
                    "roleExperience": "3",
                    "id": "21ea7f61-a9a5-4dbd-b405-e7a0449f8096"
                },

所以本质上我将一个项目分配给一个团队,然后根据我选择的团队,我想根据他们在该团队中选择一个leadDev。

我不知道如何摘下一个组合框的值,并动态应用一个过滤器,所以任何帮助将是伟大的。

网格中的每一行都是一个模型。因此,在leadDev组合框中,您只需要侦听'expand'事件,然后检索当前行模型并将该模型的值应用于过滤器。它看起来应该像这样(未选中):

Ext.create('Ext.form.ComboBox', {
                store: store
                queryMode: 'local',
                displayField: 'personName',
                valueField: 'personName',
                listeners: {
                    'expand' : function(combo) {
                         var grid = combo.up('grid');
                         var selection = grid.getSelectionModel().getSelection();
                         var currentRowModel = //get this from selection
                         combo.getStore().clearFilter(true);
                         combo.getStore().filter('teamName',currentRowModel.teamName);
                     }
                }
            })

当用户从第一个组合框中选择值时,需要更新当前模型