为什么我的ExtJS GridPanel不关注限制参数?

时间:2011-02-09 16:06:13

标签: extjs load limit store param

我有一个JsonStore:

var store = new Ext.data.JsonStore({
        root: 'Data.items',
        remoteSort: false,
        fields: ['ClockTime', 'EmpId'],
        proxy: new Ext.data.HttpProxy({
            url: AppRootPath + 'Something/GetSomething',
            method: 'POST'
        })//proxy
});//new Ext.data.JsonStore

然后我使用以下内容在此商店上调用Load:

store.load({params:{start: 0, limit: 25}});

我有一个网格来显示这些数据:

    var grid = new Ext.grid.GridPanel({
    store: store,
    title:'Employees',
    stateful: true,
    id: 'grid',
    stripeRows: true,
    stateId: 'excp_list',
    bbar: new Ext.PagingToolbar({
        store: store,       
        displayInfo: true,
        prependButtons: true,
        emptyMsg: "No records to display",
        pageSize: 25
    }),
    viewConfig: {
        forceFit: true
    },
    columns: [
        {header: "Emp Id", width: 40, dataIndex: 'EmpId', sortable: true},
        {header: "Clock Time", width: 40, dataIndex: 'ClockTime', sortable: true}
    ]
 });

我希望每页只显示25条记录/行。但它只显示一页,该页面上共有160条记录。 我错过了一些明显的东西吗?

3 个答案:

答案 0 :(得分:4)

您缺少Store / JsonReader的totalProperty。这应该是记录的总数,分页工具栏需要知道这个以计算页数等。此外,您的服务器需要发送回正确的页面和总结果计数。看起来您的服务器正在发回所有记录,并忽略了起始和限制参数。

答案 1 :(得分:3)

shane87,

简而言之,您可能在这里遗漏的“显而易见”的事情是服务器有责任检测/读取开始和限制并仅发回“限制”数量的记录

否则,您的客户端代码看起来没问题,除了您可能想要检查的totalProperty,如下面Robby的answer所述。

答案 2 :(得分:1)

在load()配置中声明的参数作为普通的HTTP参数发送。在C#中,你必须发出一个Request [“start”]和一个Request [“limit”]来获取这些参数并将它们发送到你的数据层。在大多数情况下,您的数据库应该能够分页返回的结果集/数据集,并仅将该数据发送回ExtJS。