【问题标题】:Extjs paging toolbar problemExtjs分页工具栏问题
【发布时间】:2011-08-22 06:39:08
【问题描述】:

当我尝试仅显示五行时,分页工具栏显示“显示 1-5 of [how many items I got in db]”,问题是网格实际上显示了整个 db,即使它说它显示只有5个项目。这是我的商店:

var viewOrder = Ext.create('Ext.data.Store', {
    model : 'orderModel',
    pageSize: 5,
    proxy : new Ext.data.HttpProxy({
        type : 'ajax',
    url : 'allOrderJson',
    method : 'GET',
    reader : {
        type : 'json',
        root : 'jsonArray',
        totalProperty : 'total'
    }
}),
autoLoad: false,
});

型号:

Ext.regModel('orderModel', {
    fields : [ {
        name : 'order_number',
        type : 'string'
    }, {
    name : 'status',
    type : 'string'
    }, {
    name : 'time_of_delivery',
    type : 'string'
    }, {
         name : 'last_edited',
         type : 'string'
    } ]
});

在创建网格之前,我会加载商店:

viewOrder.load({
    params : {
        start : 0,
        limit : 5,
    }
});

我的网格:

xtype : 'grid',
    id : 'incompleteorders',
    title : 'outstanding orders',
    store : viewOrder,

    columns : [ {
        text : 'order number',
        dataIndex : 'order_number',
    }, {
        text : 'status',
        dataIndex : 'status',
    }, {
        text : 'delivery date',
        dataIndex : 'time_of_delivery',
    }, {
        text : 'last edited',
        dataIndex : 'last_edited',
    }, ],
    dockedItems : [ {
        xtype : 'pagingtoolbar',
        pageSize : 5,
        store : viewOrder, 
        dock : 'bottom', 
        displayInfo : true,
        emptyMsg : 'No data to display',
    } ]

你能看看我是不是做错了什么吗?我尝试按照 sencha 文档进行操作,但显然不能正常工作。

【问题讨论】:

  • 哦,我也尝试过使用 bbar 而不是 dockedItems。

标签: extjs extjs4


【解决方案1】:

当向服务器发送 5 个项目的请求时,您是否只返回它请求的 5 个项目?您可以在服务器上进行适当的过滤。

在此处查看 totalProperty 选项:http://docs.sencha.com/ext-js/4-0/#/api/Ext.data.reader.Json

totalProperty 是指响应中包含记录总数的属性。它默认为总计,因此您的响应应该类似于:

{
    "total": 20,
    "records": [{
        "a": "foo"
    }]
}

这样做,您还需要适当地设置阅读器的根属性,在上面的示例中,它是“记录”。

【讨论】:

  • 不,我的印象是你可以把所有的数据都放在store里,让ext来处理数据的分页,不然ext怎么知道有多少页?
  • 有听起来很愚蠢的风险;如何正确设置 totalProperty?我在任何地方都能看到的唯一例子是 totalProperty : 'total' - 我的选择是什么?
  • 对,所以尝试了这个,仍然有同样的问题 - 分页工具栏中的所有内容看起来都正确,但网格仍然显示所有订单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-04
  • 2013-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多