题
我创建了一个具有分页工具栏的基本网格。由于某种原因,当我在索引0上加载时,即使文本显示“显示第1页,共5页”,“下一页”按钮也被禁用。如果我在商店的负载参数中选择高于0的内容,它允许我向前和向后分页,但是它不能正确显示页面的最大值,如果我返回第一页,下一个按钮是一次再次禁用。
有任何想法吗?
function getBugGrid(activityPanelWrapper){
var pageSize = 5;
var bugStore = new Ext.data.JsonStore({
reader: new Ext.data.JsonReader({
totalProperty: 'total_count'
}),
autoLoad: {params:{start: 0, limit: pageSize}},
autoDestroy: true,
url: '/bugs/fetch',
idProperty: 'id',
region: 'center',
root: 'data',
storeId: 'bugStore',
fields: [...]
});
var columnModel = new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [...]
});
return new Ext.grid.GridPanel({
region: 'center',
store: bugStore,
colModel: columnModel,
trackMouseOver:false,
loadMask: true,
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
listeners: {
rowclick: {
fn: function(grid, rowIndex, event) {
var bug_id = grid.store.getAt(rowIndex).id;
Ext.getCmp('activity-panel').load(activity_lines_path(bug_id));
}
}
},
bbar: new Ext.PagingToolbar({
pageSize: pageSize,
store: bugStore,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
});
}
JSON回应:
{"data":[{ bug 1 },{ bug 2 },{ bug 3 },{ bug 4 },{ bug 5 }],
"errors":{},
"total_count":25}
解决方案
您没有阅读JSONREADER中的TotalProperty ...
您需要将此配置添加到自动加载...
var bugStore = new Ext.data.JsonStore({
autoDestroy: true,
url: '/bugs/fetch',
idProperty: 'id',
root: 'data',
storeId: 'bugStore',
fields: [ ... ]
autoLoad: {params:{start: 0, limit: pagesize}}
});
您还可以在JSON商店中定义JSON阅读器:
var myStore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
totalProperty: 'total_count',
...
}),
...
});
不隶属于 StackOverflow