2

我在我的视图中有一个 ExtJS 网格,现在我确实想添加一些列过滤器......我已经在网上搜索过,虽然我没有成功。问题是如果我打开可以排序的列的子菜单等。我看不到选项过滤器。

以下代码是我的视图脚本的一部分:

Ext.define('Project.my.name.space.EventList', {
    extend: 'Ext.form.Panel',
    require: 'Ext.ux.grid.FiltersFeature',

    bodyPadding: 10,
    title: Lang.Main.EventsAndRegistration,
    layout: {
        align: 'stretch',
        type: 'vbox'
    },

    initComponent: function () {
        var me = this;

        Ext.applyIf(me, {
            items: [

                ...

                {
                xtype: 'gridpanel',
                title: '',
                store: { proxy: { type: 'direct' } },
                flex: 1,
                features: [filtersCfg],
                columns: [
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'Title',
                    text: Lang.Main.CourseTitle,
                    flex: 1,
                    filterable: true
                },
                {
                    xtype: 'datecolumn',
                    dataIndex: 'StartDate',
                    text: Lang.Main.StartDate,
                    format: Lang.Main.DateFormatJS,
                    flex: 1,
                    filter: { type: 'date' }
                },
                {
                    xtype: 'datecolumn',
                    dataIndex: 'EndDate',
                    text: Lang.Main.EndDate,
                    format: Lang.Main.DateFormatJS,
                    flex: 1, // TODO: filter
                },
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'Participants',
                    text: Lang.Main.Participants,
                    flex: 1
                },
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'LocationName',
                    text: Lang.Main.Location,
                    flex: 1
                },
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'Status',
                    text: Lang.Main.Status,
                    flex: 1, // TODO: filter
                }],
                dockedItems: [{
                    xtype: 'toolbar',
                    items: [{
                        icon: 'Design/icons/user_add.png',
                        text: Lang.Main.RegisterForEvent,
                        disabled: true
                    },
                    {
                        icon: 'Design/icons/user_delete.png',
                        text: Lang.Main.Unregister,
                        disabled: true
                    },
                    {
                        icon: 'Design/icons/application_view_list.png',
                        text: Lang.Main.Show,
                        disabled: true
                    },
                    {
                        icon: 'Design/icons/calendar_edit.png',
                        text: Lang.Main.EditButtonText,
                        hidden: true,
                        disabled: true
                    },
                    {
                        icon: 'Design/icons/calendar_add.png',
                        text: Lang.Main.PlanCourse,
                        hidden: true
                    }]
                }]
                }
            ]
        });

        me.callParent(arguments);

        ...

        this.grid = this.query('gridpanel')[0];

        this.grid.on('selectionchange', function (view, records) {
            var selection = me.grid.getSelectionModel().getSelection();
            var event = (selection.length == 1) ? selection[0] : null;
            var registered = event != null && event.data.Registered;
            me.registerButton.setDisabled(registered);
            me.unregisterButton.setDisabled(!registered);
            me.showButton.setDisabled(!records.length);
            me.editButton.setDisabled(!records.length);            

        });
    }
});

这也是代码的pastebin链接:http: //pastebin.com/USivWX9S

更新

刚刚在调试时注意到我FiltersFeature.js在这一行的文件中收到了一个 JS 错误:

createFilters: function() {
        var me = this,
            hadFilters = me.filters.getCount(),
            grid = me.getGridPanel(),
            filters = me.createFiltersCollection(),
            model = grid.store.model,
            fields = model.prototype.fields,
Uncaught TypeError: Cannot read property 'prototype' of undefined
            field,
            filter,
            state;

请帮我!

4

1 回答 1

1

有几个语法错误。

  • FiltersFeature是网格特征而不是组件。
  • 您不能extend使用对象文字(如果我错了,请纠正我)

像这样使用过滤器:

var filtersCfg = {
    ftype: 'filters',
    local: true,
    filters: [{
        type: 'numeric',
        dataIndex: 'id'
    }]
};

var grid = Ext.create('Ext.grid.Panel', {
     features: [filtersCfg]
});
于 2013-03-08T11:21:31.003 回答