【问题标题】:Store does not load inside a gridpanel - ExtJS存储不会在网格面板内加载 - ExtJS
【发布时间】:2014-01-04 02:50:10
【问题描述】:

iO! 我知道这个问题已经被问过很多次了,但我仍然无法弄清楚我的问题来自哪里。 我只是想从 PostGreSQL 数据库加载数据并将其显示在 ExtJS 网格中。

我的商店:

var getreports = Ext.create('Ext.data.JsonStore', {
    // store configs
    autoDestroy: true,
    proxy: {
        type: 'ajax',
        url: 'http://129.129.129.15:81/getlistreports',
        reader: {
            type: 'json',
            idProperty: 'id_consult',
            totalProperty: 'total'
        }
    },
    remoteSort: false,
    pageSize: 50,
});

我的网格(嵌入边框布局):

            {
            region: 'center',
            //xtype: 'container',
            items: [
            Ext.create('Ext.grid.Panel', {
            features: [filters],
            store: getreports,
            emptyText: 'Aucune donnée n\'a été trouvée',
            columns: [
                { 
                text: 'Nom',
                dataIndex: 'id_consult', 
                filter: 
                    { 
                    type: 'string',
                    }, 
                },
                { 
                text: 'génération',
                dataIndex: 'typeentity',
                flex: 1,
                filter: 
                    { 
                    type: 'string',
                    }, 
                },
                { 
                text: 'Etat',
                dataIndex: 'typeref',
                filter: 
                    { 
                    type: 'list',
                    }, 
                },
            ]
            }),
            ]
            },

以及它应该读取的 JSON。我已经让监听器在控制台日志中显示 AJAX 调用的内容并显示一些内容,所以我猜问题不是来自它。

[{"id_consult":"1","typeref":"Territorial","typeentity":"BH"},
{"id_consult":"2","typeref":"Territorial","typeentity":"BOOS"},
{"id_consult":"3","typeref":"Territorial","typeentity":"BOB"}]

最后:

getreports.load(); 

函数结束时

加载页面时,它显示加载“弹出”,但随后什么也不显示,并显示我已声明的 EmptyText。
另请注意,当我在网格内声明商店时过滤器不起作用(如果我删除它,我可以看到它们)。

对此有什么建议吗:)?

【问题讨论】:

    标签: javascript extjs extjs4 store gridpanel


    【解决方案1】:

    您的列定义是一团糟(很多尾随逗号),但这不是最终的问题。网格没有加载任何数据,因为商店在加载数据后没有创建任何记录。您需要将fields 配置添加到您的商店定义中,或者创建一个可以应用于商店的model 定义。执行此操作后,您会发现它有效(请参见下面链接的示例)

    fields: ['id_consult', 'typeref', 'typeentity'],
    

    您的代码运行示例:https://fiddle.sencha.com/#fiddle/282

    【讨论】:

    • 非常感谢!是的,对于逗号,主要原因是我删除了那里的几部分代码以使其更清晰,但你是对的,那是一团糟:(!
    【解决方案2】:

    我认为您的列定义错误。尝试将列更改为以下内容:

    columns: [
    {
        header: 'Nom',
        dataIndex: 'id_consult',
        flex: 1
    },
    ...
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 2011-02-15
      相关资源
      最近更新 更多