javascript - ExtJS grid filters: how can I load 'list' filter options from external json? - Stack Overflow

I have a ExtJS (4.0) grid and it works fine. Now I want it to advance it a bit by adding filters to it.

I have a ExtJS (4.0) grid and it works fine. Now I want it to advance it a bit by adding filters to it. I want users to be able to filter items by the status.

I have created the following store:

var status_store = Ext.create('Ext.data.Store', {
    model: 'Statuses',
    proxy: {
        type: 'ajax',
        url: '/json/statuses/',
        reader: 'json'
    }
});

and I can see it loads, /json/statuses/ will return the following json object:

[
  {
    "name": "OK",
    "isActive": true
  },
  {
    "name": "Outdated",
    "isActive": true
  },
  {
    "name": "New",
    "isActive": true
  }
]

Now I define the filters:

var filters = {
    ftype: 'filters',
    encode: encode,
    local: local,
    filters: [{
        type: 'list',
        dataIndex: 'name',
        store: 'status_store',
        labelField: 'name'          
    }]
};

and add the filter to my column definition:

{text: 'Status', width: 120, dataIndex: 'status', sortable: true, filterable: true, filter: {type: 'list'}},

What happens is I get the following error when the grid loads:

Uncaught TypeError: Object json has no method 'read' (ext-all-debug.js:25702)

and when I click on the column header for the menu:

Uncaught TypeError: Object status_store has no method 'on' (ListMenu.js:69)

How can I fix this or am I doing something conceptually wrong?

Here is the full quote of my code just in case:

I have a ExtJS (4.0) grid and it works fine. Now I want it to advance it a bit by adding filters to it. I want users to be able to filter items by the status.

I have created the following store:

var status_store = Ext.create('Ext.data.Store', {
    model: 'Statuses',
    proxy: {
        type: 'ajax',
        url: '/json/statuses/',
        reader: 'json'
    }
});

and I can see it loads, /json/statuses/ will return the following json object:

[
  {
    "name": "OK",
    "isActive": true
  },
  {
    "name": "Outdated",
    "isActive": true
  },
  {
    "name": "New",
    "isActive": true
  }
]

Now I define the filters:

var filters = {
    ftype: 'filters',
    encode: encode,
    local: local,
    filters: [{
        type: 'list',
        dataIndex: 'name',
        store: 'status_store',
        labelField: 'name'          
    }]
};

and add the filter to my column definition:

{text: 'Status', width: 120, dataIndex: 'status', sortable: true, filterable: true, filter: {type: 'list'}},

What happens is I get the following error when the grid loads:

Uncaught TypeError: Object json has no method 'read' (ext-all-debug.js:25702)

and when I click on the column header for the menu:

Uncaught TypeError: Object status_store has no method 'on' (ListMenu.js:69)

How can I fix this or am I doing something conceptually wrong?

Here is the full quote of my code just in case: http://pastebin./SNn6gFJz

Share Improve this question edited May 24, 2013 at 19:01 Darin Kolev 3,40913 gold badges33 silver badges47 bronze badges asked May 14, 2011 at 19:43 abolotnovabolotnov 4,3229 gold badges63 silver badges90 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Thanks for Diagnosing the problem. The 4.1 fix is this modify ListMenu.js

in the else part of the constructor

replace

        me.store.on('load', me.onLoad, me);

with

        // add a listener to the store object
        var storeObject = Ext.StoreMgr.lookup(me.store);
        storeObject.on('load', me.onLoad, me);
        me.store = storeObject;
filters: [{
             type: 'list',
             dataIndex: 'name',
             store: 'status_store',
             labelField: 'name' ,
             options:[a,b]
         }]

You also have to give the options in list filters.

I was having a similar problem. I followed the @jd ment on the other answer here but the options menu just said "loading...". I resolved it with a bit of a hack here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744691065a4588212.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信