javascript - EXTJS Load JSONStore to grid after asynchronous get - Stack Overflow

I have a JSON store that I would like to auto load into a grid.panel. Unfortunately, after it pletes th

I have a JSON store that I would like to auto load into a grid.panel. Unfortunately, after it pletes the asynchronous get, nothing is populated in the grid. Firebug shows that the JSON was retrieved successfully.

store:

var datasetStore = new Ext.data.JsonStore({
    root: 'rows',
    fields: ['griddap', 'Subset', 'tabledap', 'Make A Graph', 'wms', 'Title', 'Summary', 'Info', 'Background Info', 'RSS', 'Email', 'Institution', 'Dataset ID'],
    proxy: new Ext.data.HttpProxy({
        url: 'http://localhost:8080/proxy.php?u=.json'
        }),
    autoLoad: true
});

grid:

var datasetListingGridPanel = new Ext.grid.GridPanel({
        id: 'datasetListingGridPanel',
        preventHeader: true,
        store: datasetStore,
        layout: 'fit',
        viewConfig: {
            forceFit:true,
            fitcontainer:true
        },
        columns: 
        [
            {
                header: 'Dataset Title', 
                dataIndex: 'Title'
            }
        ]
        });

EDIT - JSON

{
    "table": {
        "columnNames": ["griddap", "Subset", "tabledap", "Make A Graph", "wms", "Title", "Summary", "Info", "Background Info", "RSS", "Email", "Institution", "Dataset ID"],
        "columnTypes": ["String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String"],
        "rows": [
            ["", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["", "", "", "", "", "", "", "", "", "", "", "", ""]
         ]
    }
}

I took out the values as they were very long.

Any ideas on what is going wrong?

I have a JSON store that I would like to auto load into a grid.panel. Unfortunately, after it pletes the asynchronous get, nothing is populated in the grid. Firebug shows that the JSON was retrieved successfully.

store:

var datasetStore = new Ext.data.JsonStore({
    root: 'rows',
    fields: ['griddap', 'Subset', 'tabledap', 'Make A Graph', 'wms', 'Title', 'Summary', 'Info', 'Background Info', 'RSS', 'Email', 'Institution', 'Dataset ID'],
    proxy: new Ext.data.HttpProxy({
        url: 'http://localhost:8080/proxy.php?u=http://coastwatch.pfeg.noaa.gov/erddap/info/index.json'
        }),
    autoLoad: true
});

grid:

var datasetListingGridPanel = new Ext.grid.GridPanel({
        id: 'datasetListingGridPanel',
        preventHeader: true,
        store: datasetStore,
        layout: 'fit',
        viewConfig: {
            forceFit:true,
            fitcontainer:true
        },
        columns: 
        [
            {
                header: 'Dataset Title', 
                dataIndex: 'Title'
            }
        ]
        });

EDIT - JSON

{
    "table": {
        "columnNames": ["griddap", "Subset", "tabledap", "Make A Graph", "wms", "Title", "Summary", "Info", "Background Info", "RSS", "Email", "Institution", "Dataset ID"],
        "columnTypes": ["String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String"],
        "rows": [
            ["", "", "", "", "", "", "", "", "", "", "", "", ""],
            ["", "", "", "", "", "", "", "", "", "", "", "", ""]
         ]
    }
}

I took out the values as they were very long.

Any ideas on what is going wrong?

Share Improve this question edited Jan 31, 2013 at 14:25 blong 2,7038 gold badges47 silver badges114 bronze badges asked Nov 23, 2011 at 16:51 gberg927gberg927 1,6869 gold badges38 silver badges52 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

Since you are using JsonStore it is apparent you are still on ExtJS-3 (rather than 4) and therefore the following link is still relevant:

http://www.sencha./learn/grid-faq/

That being said, looking at your JSON, the problem is that the root you are specifying, "rows", is not a top level property: rather it is nested inside of the "table" property.

Also see: extJS: reading a nested JSON

Which in turn references this: http://docs.sencha./ext-js/3-4/#!/api/Ext.data.JsonReader

Below are a number of options:

  1. Switch the server side code that returns the JSON to return the data with "rows" as a top level property
  2. Make an Ajax call for the data, parse it manually, then feed it to your store
  3. Extend (or look for an existing extension) the necessary ExtJS ponent (JsonReader?) so that it can work with the data as is, but possibly you can specify the "root" property as "table.rows"

This is because the store's load is asynchronous. Thus, the grid loads first and finally the stores, where the data you require for the grid is.

This discussion could be helpful for you: http://www.sencha./forum/showthread.php?119836-Store-asynchronous-loading-and-Form-loading/page2

Use of callback function could be a solution for you too:

yourStore.load({  
  callback: function() {  
    //here you can be sure that the store is loaded.  
    }  
});

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信