Extjs过滤无法正常工作

Extjs过滤无法正常工作

本文介绍了Extjs过滤无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to ExtJS. I have written a code for applying filtering in a Grid, but it is not working properly. Attaching the code snippet which I have written for applying filtering.Without filters, the grid is properly displayed at the panel.

        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

I am using extjs-4.2.2

推荐答案

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

In browser console, you should have gotten a 404 error, because "feature/filters.js couldn't be loaded". This is because ftype:'filters' does not provide information which file ExtJS has to include to have the required javascript available. You can load the file manually before applying an ftype:

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

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

which tells ExtJS to load the file src/ux/grid/FiltersFeature.js, or you can take the approach without ftype:

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

这篇关于Extjs过滤无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:54