【问题标题】:Why isn't my ExtJS GridPanel paying attention to the limit parameter?为什么我的 ExtJS GridPanel 不关注 limit 参数?
【发布时间】:2011-06-24 06:13:45
【问题描述】:

我有一个 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 条记录。 我在这里遗漏了什么明显的东西吗?

【问题讨论】:

    标签: extjs load limit store param


    【解决方案1】:

    肖恩87,

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您缺少 Store/JsonReader 的 totalProperty。这应该是记录总数,分页工具栏需要知道这一点才能计算页数等。您的服务器还需要发回正确的页面和总结果数。看起来您的服务器正在发回所有记录并且忽略了 start 和 limit 参数。

        【讨论】:

        • +1 但如果未指定,JsonReader 的 totalProperty 默认为 'total'。因此,在您的 JsonReader 配置中指定它不是强制。 (我同意服务器响应是否包含此属性值得查看)
        • 引用totalProperty - dev.sencha.com/deploy/dev/docs/…
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多