问题
Instead of retrieving a single row of data from my store, how can I modify the following code to retrieve all records?
var store = Ext.data.StoreManager.lookup('MyStore');
store.setProxy({
type: 'pagingmemory',
data: store.getAt(0)
});
store.load();
Any thoughts?
回答1:
You can use store.getRange()
or you can use store.data.items
. For the getRange()
call, passing no parameters just defaults to 0 and the last record in the store.
回答2:
I think this is not complete true, since getRange()
will retrieve all the records from a store first page.
If your store has pages of 50 records per page, then store.getRange()
will give you only the first 50 records.
回答3:
store.getRange()
will only retrieve the page currently worked on if the grid is not defined to have a buffered store. Store can be set as buffered by:
(buffered: true)
But that will decrease the performance since the whole page will be buffered even if a single page will be retrieved.
The most efficient way that comes to my mind is:
var pageSize = store.pageSize // will return the page size.
var totalCount = store.totalCount // This will return total no of items
for (var i=0; i<(totalCount/pageSize)+1;i++) {
store.loadPage(i) // this will set the current page of the store to i variable.
....
....
}
回答4:
This will reload the store with all records:
store.load({start:0, limit: store.totalCount, page:1});
Take all records from store:
var records = store.getRange();`
来源:https://stackoverflow.com/questions/18340026/simply-retrieving-all-records-from-a-store