Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

extjs4 - Extjs Grid Filter - Dynamic ListFilter

I am trying to implement Ext.ux.grid.filter.ListFilter using a data store (rather than a hardcoded list) as covered here in the ExtJS 4 API. The data comes in fine and I see a filter option on this column but it just says "Loading..." where the filter options are supposed to be:

Loading...

I am pretty sure I have this configured as per the API specs but have not had any luck with this. Has anyone implemented this correctly?

The store I use to get the filter options is set up like this:

// get the levels for filtering
var levelStore = Ext.create('Ext.data.Store', {
    fields: ['levels'],
    proxy: {
        type: 'ajax', 
        url: '../json?queryName=levels',
        reader: 'json'
    },
    autoLoad: true
});

I implemented the filter config in the column like so:

{
header: 'Level',
dataIndex: 'levels',
width: 160,
sortable: true,
filter: {
    type: 'list',
    store: levelStore
}

Some thoughts I had:

Do I need my filter option data store to have a specific column title, like "name" instead of "level"?

Is this trying to get the store options before they are loaded from ajax, and there is some unspecified way of telling it to load these filter options after the ajax is returned?

Do I need to implement my filter configuration separate from the column config to use this one? (all my other filter configurations, are done right in the column config and seem to work fine)

EDIT:

The json response looks something like this, not sure if it is causing the trouble:

[{"levels":"Level 1"},{"levels":"Level 2"},{"levels":"Level 3"}]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have it resolved now. I ended up configuring the filter with an empty options array options: [] and then put a callback on the store that adds the filter options to the empty options array. Like this:

The column model (with filter config):

{
    header: 'Level',
    dataIndex: 'levels',
    itemId: 'levels',
    width: 160,
    sortable: true,
    filter: {
        type: 'list',
        options: [],
        phpMode: true,
    }
}

The store:

var levelStore = Ext.create('Ext.data.Store', {
    fields: ['levels'],
    proxy: {
        type: 'ajax', 
        url: '../json?queryName=levels',
        reader: 'json'
    },
    autoLoad: {
        callback: function() {
            grid.getView().getHeaderCt().child('#levels').initialConfig.filter.options = levelStore.collect('levels');
        }
    }
});

('grid' is the variable that I named my grid with the filters)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...