我试图使商店的pageSize限制为1。我在网格中有10个项目,虽然分页机制正确地显示10个中的1个,10个中的2个等,但网格仍然显示所有10个项目。我还尝试在json中返回"total"属性为1,但这仍然不起作用。什么好主意吗?
文档中的示例也不是很有帮助,因为它显示了源代码,但是实时预览是空的。
var photos = new Ext.data.Store({
model: 'Photos',
autoLoad: true,
pageSize: 1
});
var photosGrid = Ext.create('Ext.grid.Panel', {
id: 'PhotoGrid',
store: photos,
columns: [
{ text: "Filename", width: 200, dataIndex: 'filename' }
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: photos,
dock: 'bottom',
displayInfo: true
}],
region: 'center',
border: 0,
overCls: 'row-pointer'
});
嘿,你的问题是你可能会返回json中的所有10个项目,分页支持你必须自己实现,所有分页所做的是调用加载存储与特定参数,如页面的限制和页面开始索引。您必须在后端使用这些参数来一次发送一个项目。雪儿伴侣。
编辑
//this is the model we will be using in the store
Ext.define('Page', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
]
});
var data = null;
var store = null;
Ext.Ajax.request({
url: 'someurl',
success: function(result){
data = Ext.decode(result.responseText);
store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'Page',
pageSize: 1,
data : data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'pages'//this has to be as the root from your json
}
}
});
}
});
这是在你的脚本格式化json查询的问题。当你使用extjs与pageSize,它发送查询参数(page
&limit
,我记得)。在服务器端脚本中,您必须检查它们是否存在,如果存在,更改查询以添加limit
子句(或在其他数据库中等效)。