0

我想获得一个带有 extjs4 和 ac# 后端的无限滚动网格......我在我的控制器中设置代理 api..

我的模型:

Ext.define('appname.model.training.course.TrainingRequirementList', {
    extend: 'Ext.data.Model',
    idProperty: 'ID',
    fields: [
        { name: 'ID', type: 'int', convert: null },
        { name: 'EmployeeName', type: 'string' },
        { name: 'Description', type: 'string' },
        { name: 'StatusText', type: 'string' },
        { name: 'Status', type: 'int' },
        { name: 'Priority', type: 'string' },
        { name: 'Date', type: 'string' },
        { name: 'Cost', type: 'string' },
        { name: 'CanApprove', type: 'bool' },
        { name: 'CanRequest', type: 'bool' },
        { name: 'ConfirmStatus', type: 'string' },
        { name: 'PlanId', type: 'int'}
    ]

});

我的网格:

{
    xtype: 'gridpanel',
    flex: 1,
    padding: '0 10 10 10',
    minHeight: 200,
    verticalScroller: {
        xtype: 'paginggridscroller'
    },
    store: {
        model: 'appname.model.training.course.TrainingRequirementList',
        pageSize: 200,
        autoLoad: true,
        buffered: true,
        remoteSort: true,
        sorters: {
            property: 'Date',
            direction: 'DESC'
        },

        proxy: {
            type: 'direct',
            extraParams: {
                total: 50000
            },
            reader: {
                type: 'json',
                root: 'ID',
                totalProperty: 'TotalCount'
            },
            simpleSortMode: true
        }
    },
    columns:
        [{
            text: Lang.Main.Employeee,
            dataIndex: 'EmployeeName',
            flex: 1,
            filterable: true
        },
        {
            text: Lang.Main.Course,
            dataIndex: 'Description',
            flex: 1,
            filterable: true
        },
        {
            text: Lang.Main.Status,
            dataIndex: 'StatusText',
            flex: 1,
            filterable: true
        },
        {
            text: Lang.Main.Priority,
            dataIndex: 'Priority',
            flex: 1
        },
        {
            text: Lang.Main.Date,
            dataIndex: 'Date',
            flex: 1
        },
        {
            text: Lang.Main.Cost,
            dataIndex: 'Cost',
            flex: 1,
            filterable: true
        },
        {
            text: Lang.Main.Actions,
            flex: 1,
            align: 'center',
            xtype: 'actioncolumn',
            width: 50,
            items: [{
                icon: 'Design/icons/cog_edit.png',
                tooltip: Lang.Main.Open,
                handler: function (grid, rowIndex, colIndex, item) {
                    this.onGridOpen(grid.getStore().getAt(rowIndex));
                }
            }]
        }],      
    selModel: { mode: 'MULTI', selType: 'checkboxmodel' },
}

在控制器中设置代理:

view.grid.getStore().setProxy({
            type: 'direct', 
            model: 'appname.model.training.course.TrainingRequirementList', 
            api: { read: SCT.Service.Training.Plan.GetFilteredRequirements }, 
            extraParams: { total: 50000 }, 
            reader: {
                type: 'json',
                root: 'ID',
                totalProperty: 'TotalCount'
            },
            simpleSortMode: true
        });

关于我的观点的其他信息:

Ext.define('appname.view.training.course.TrainingRequirements',
    {
        extend: 'Ext.panel.Panel',
        require: [ 'Ext.grid.PagingScroller'],

我的网格只加载前 200 行,滚动条只有 200 行那么大.. :/ ...

服务器响应具有如下条目:

{"ID":99,"PlanId":23,"firstname":"name","lastname":"name","Comment":"","Status":3,"ConfirmType":0,"Priority":"entry","DesiredDate":null,"StartDate":new Date(1354107600000),"ActualCost":180,"EstimatedCost":0,"row":201,"TotalCount":8568,"EmployeeName":"some, name","Description":"","StatusText":"state","Date":"28.11.2012","Cost":"EUR 180"}

我错过了什么???

更新

当我向下滚动时,脚本也在加载第二页.. 仅此而已...

如果您需要更多信息,请随时询问

4

1 回答 1

1

您的服务器是否TotalCount在响应中包含正确的值?

编辑:

根据您的读者的配置,您的服务器应该使用这种格式的数据进行响应(当然您的响应也应该是有效的 JSON,这里使用 Javascript 进行说明):

{
    // total property at the root level of response object
    TotalCount: 8568,

    // root for items data, configured as "ID" in your reader (you should probably
    // change that to something like "records" or "data" to better express meaning)
    ID: [
        // individual fields data
        {ID: 1, EmployeeName: 'Foo', ...},
        {ID: 2, EmployeeName: 'Bar', ...},
        ...
    ]

    // if you had, for example, a successProperty, it would go here too
    ,success: true
}

在您的情况下,您似乎TotalCount混合在每个项目数据中?

你对服务器端的实现是正确的:它应该只是记录的总数,所以就像COUNT(*)在数据库中一样。

还有一件事:new Date(1354107600000)不是有效的 JSON。解码 JSON 后,您应该使用字符串并将其转换为日期。例如,在您的模型中,您可以将字段类型配置为让 Ext 为您处理:{name: 'Date', type: 'date', format: 'd.m.Y'}

于 2013-06-05T09:40:53.163 回答