Why isn't my ExtJS GridPanel paying attention to the limit parameter?
I have a JsonStore:
var store = new Ext.data.JsonStore({
root: 'D开发者_C百科ata.items',
remoteSort: false,
fields: ['ClockTime', 'EmpId'],
proxy: new Ext.data.HttpProxy({
url: AppRootPath + 'Something/GetSomething',
method: 'POST'
})//proxy
});//new Ext.data.JsonStore
I then call Load on this store with the following:
store.load({params:{start: 0, limit: 25}});
I have a grid to display this data in:
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}
]
});
I expected this to only display 25 records/rows per page. however it only displays one page with the total 160 records on this page. Am I missing something obvious here?
You are missing the totalProperty for the Store/JsonReader. This should be the total number of records, the paging toolbar needs to know this to calculate the number of pages, etc. Also Your server needs to send back the correct page and the total Result count. Looks like your server is sending back all the records and is ignoring the start and limit parameters.
shane87,
In short, the "obvious" thing that you may be missing here is the fact that it is the server's responsibility to detect/read start and limit and send back only 'limit' number of records.
Otherwise, your client code looks OK, except for the totalProperty that you may want to check as mentioned by Robby's answer below.
Params declared in the load() config are sent as plain HTTP params. In C# you would have to issue a Request["start"] and a Request["limit"] to get those params and them send them along to your data tier. In most cases your database should be able to page returned resultsets/datasets and send only that data back to ExtJS.
精彩评论