Extjs过滤不正常

时间:2016-06-16 06:31:39

标签: extjs extjs4 extjs4.1 extjs4.2 extjs5

我是ExtJS的新手。我编写了一个在Grid中应用过滤的代码,但它无法正常工作。附上我为编写应用过滤而编写的代码段。 如果没有过滤器,则会在面板上正确显示网格。

        Ext.create('Ext.data.Store', {
        storeId: 'userDetailsStore',
        fields: ['username', 'firstname', 'lastname', 'role', 'activeuser'],
        data: {'items': [
                {"username": 'USER1', "USER1-firstname": "firstname", "lastname": "USER1-lastname",
                    "role": 'Admin', "activeuser": 'Y'},
                {"username": 'USER2', "firstname": "USER2-firstname", "lastname": "USER2-lastname",
                    "role": 'Type1', "activeuser": 'Y'},
                {"username": 'USER3', "firstname": "USER3-firstname", "lastname": "USER3-lastname",
                    "role": 'Type2', "activeuser": 'Y'},
                {"username": 'USER4', "firstname": "USER4-firstname", "lastname": "USER4-lastname",
                    "role": 'Type3', "activeuser": 'Y'},
                {"username": 'USER5', "firstname": "USER5-firstname", "lastname": "USER5-lastname",
                    "role": 'Admin', "activeuser": 'Y'},
                {"username": 'USER6', "firstname": "USER6-firstname", "lastname": "USER6-lastname",
                    "role": 'Type4', "activeuser": 'Y'}
            ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });

    var filters = Ext.create('Ext.ux.grid.FiltersFeature',
            {
        // ftype: 'filters',
        encode: false,
        autoReload: false,
        local: true,
        filters: [{
                type: 'string',
                dataIndex: 'username'
            }, {
                type: 'string',
                dataIndex: 'firstname',
                disabled: true
            }, {
                type: 'string',
                dataIndex: 'lastname'
            }, {
                type: 'list',
                dataIndex: 'role',
                options: ['Admin', 'Type1', 'Type2', 'Type3', 'Type4'],
                phpMode: true
            }, {
                type: 'string',
                dataIndex: 'activeuser'
            }]
    };

    var user_view_grid = new Ext.create('Ext.grid.Panel', {
        title: 'User Details',
        border: false,
        align: 'stretch',
        store: Ext.data.StoreManager.lookup('userDetailsStore'),
        loadMask: true,
        features: [filters],
        bbar: Ext.create('Ext.toolbar.Paging', {
            store: Ext.data.StoreManager.lookup('userDetailsStore')
        }),
        columns: [
            {header: 'Username', dataIndex: 'username', flex: 1},
            {header: 'FirstName', dataIndex: 'firstname', flex: 1},
            {header: 'LastName', dataIndex: 'lastname', flex: 1},
            {header: 'Role', dataIndex: 'role', flex: 1},
            {header: 'ActiveUser', dataIndex: 'activeuser', align: 'center'}
        ],
        height: 200
    });

    var user_view_panel = new Ext.Panel({
        region: 'north',
        margins: '2 0 0 0',
        cmargins: '5 5 0 0',
        height: 200,
        split: true,
        collapsible: false,
        border: true,
        xtype: 'panel',
        bodyStyle:
                {
                    "background-color": "#F8F8F8",
                    "padding-left": "5px",
                    "padding-right": "5px",
                    "padding-bottom": "5px"
                },
        items: [
            user_view_grid
        ]
    });

    Ext.create('Ext.container.Viewport', {
        layout: 'fit',
        items: [{
                layout: 'border',
                defaults: {
                    collapsible: false,
                    split: false,
                    bodyStyle: 'padding:2px'
                },
                items: [
                    {
                        collapsible: false,
                        region: 'center',
                        title: 'User Management',
                        bodyStyle: {"background-color": "#F8F8F8"},
                        layout: {
                            type: 'border',
                            align: 'stretch'
                        },
                        items: [
                            user_view_panel
                        ]
                    }
                ]
            }],
        renderTo: Ext.getBody()
    });

我正在使用extjs-4.2.2

enter image description here

1 个答案:

答案 0 :(得分:0)

在浏览器控制台中,您应该收到404错误,因为" feature/filters.js无法加载"。这是因为ftype:'filters'不提供ExtJS必须包含哪些文件才能获得所需的javascript的信息。您可以在应用ftype之前手动加载文件:

Ext.require('Ext.ux.grid.FiltersFeature');

告诉ExtJS加载文件src/ux/grid/FiltersFeature.js,或者您可以在没有ftype的情况下采用该方法:

var filters = Ext.create('Ext.ux.grid.FiltersFeature',{
    encode: false,
    ...