我已经为分页编写了extjs代码。它向我展示了网格中的所有数据,但我设置了itemsPerPage = 2。我认为这是一个小错误,但我对extjs和所有的东西都是新手,所以我不能弄清楚。我试过了,但到目前为止还没成功。
Ext.onReady(function () {
var itemsPerPage = 2; // set the number of items you want per page
var store = Ext.create('Ext.data.Store', {
storeId: 'employeeStore',
autoLoad: false,
pageSize: itemsPerPage,
fields: ['firstname', 'lastname', 'seniority', 'dep', 'hired'],
data: [{
firstname: "Michael",
lastname: "Scott"
}, {
firstname: "Dwight",
lastname: "Schrute"
}, {
firstname: "Jim",
lastname: "Halpert"
}, {
firstname: "Kevin",
lastname: "Malone"
}, {
firstname: "Angela",
lastname: "Martin"
}],
proxy: {
type: 'ajax',
url: 'example.json', // url that will load data with respect to start and limit params
reader: {
type: 'json',
root: 'blah',
totalProperty: 'total'
}
}
});
// specify segment of data you want to load using params
store.load({
params:{
start:0,
limit: itemsPerPage
}
});
Ext.create('Ext.grid.Panel', {
title: 'Pagination',
store: store,
columns: [{
text: 'First Name',
dataIndex: 'firstname',
field: 'textfield',
flex : 1,
}, {
text: 'Last Name',
dataIndex: 'lastname',
flex : 1,
field:{
xtype:'textfield',
allowBlank:false
}
}],
id : 'SimpleGrid',
width: 500,
dockedItems: [{
xtype: 'pagingtoolbar',
store: store, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});});
要使用分页,请在第一次加载存储区时将分页要求传递给服务器。
store.load({
params: {
// specify params for the first page load if using paging
start: 0,
limit: myPageSize,
// other params
foo: 'bar'
}});
这里我用的是extjs + Grid + Panel。
致以亲切的问候,
发布于 2014-10-09 23:04:49
如果您查看comment to url字段:
proxy: {
...
url: 'example.json', // url that will load data with respect to start and limit params
...
}extjs在加载所有需要的参数时向服务器发送请求。例如: extjs,因此您应该将其限制在服务器上,然后发送回example.json?start=0&limit=2&page=1
在这里,您可以查看工作示例,其中限制是手动处理的。
http://jsfiddle.net/jardalu/TE4ah/
https://stackoverflow.com/questions/26280776
复制相似问题