-
19 May 2011 7:56 AM #21
OK, for those having trouble getting this to work, here's my set-up. I've included stevil's fix too, for good measure.

As long as your data is formatted properly, you should NEVER get either of those pesky errors.PHP Code:Ext.onReady(function(){
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id','name','balance'],
idProperty: 'id'
});
var store = Ext.create('Ext.data.Store', {
model: 'User',
pageSize: 60,
buffered: true,
remoteSort: true,
purgePageCount: 5,
proxy: {
type: 'ajax',
url: 'yourURLHere',
reader: {
type: 'json',
root: 'data',
totalProperty: 'total'
},
simpleSortMode: true
}
});
var grid = Ext.create('Ext.grid.Panel', {
id: 'myGrid',
store: store,
verticalScroller: {
xtype: 'paginggridscroller',
activePrefetch: true // preload new set just before you reach the end
},
invalidateScrollerOnRefresh: false,
columns: [
{
dataIndex: 'id',
header: 'ID',
width: 60,
flex:6
},{
dataIndex: 'name',
header: 'Name',
width: 150,
flex:15
},{
dataIndex: 'balance',
header: 'Balance',
format: '$0,000.00',
width: 80,
flex:8
}
]
});
var vp = Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
layout: 'fit',
items: [
{
title: 'Infinite Scroll Test',
layout: 'fit',
items: [grid]
}
]
});
vp.show();
store.guaranteeRange(0, store.pageSize - 1);
// probably not necessary in real-life situations, but just in case...
// add this override to handle empty data
Ext.override(Ext.data.Store, {
onGuaranteedRange: function() {
var me = this,
totalCount = me.getTotalCount(),
start = me.requestStart,
end = ((totalCount - 1) < me.requestEnd) ? totalCount - 1 : me.requestEnd,
range = [],
record,
i = start;
if (start > end) {
me.guaranteedStart = start;
me.guaranteedEnd = undefined;
me.totalCount = undefined;
}
else if (start !== me.guaranteedStart && end !== me.guaranteedEnd) {
me.guaranteedStart = start;
me.guaranteedEnd = end;
for (; i <= end; i++) {
record = me.prefetchData.getByKey(i);
//should never happen
if (!record) {
Ext.Error.raise("Record was not found and store said it was guaranteed");
}
range.push(record);
}
me.fireEvent('guaranteedrange', range, start, end);
if (me.cb) {
me.cb.call(me.scope || me, range);
}
}
me.unmask();
}
});
Ext.Error.handle = function (err) {
if (err.sourceMethod == "onGuaranteedRange") {
return true;
}
};
});
You should grab a data set based on the start and limit params that are automatically sent, and the response should look something like this: {"data":[{"id":"1","name":"Foo Bar","balance":500},...],"total":<the total of ALL the data>}
The grid will load a new set just before you scroll to the end of each page. The last page will contain a smaller set of data, but it loads without error.
Hope this helps!
-
19 May 2011 9:29 AM #22
By the way, 4.0.1 strips this debug code from ext-all, so the workaround is not needed there. It is needed with ext-all-debug, or running from src.
I really wish that, included with the official build were included an un-minified "all".js, so that the ONLY difference is minification, and not the stripping of code.
so, ext-all-debug.js, ext-all.js, ext-all-min.js (or something like it) would be my strong preference.
stevil
-
20 May 2011 10:12 PM #23
-
10 Jun 2011 1:59 AM #24
+1
Please fix it. store.guaranteeRange() should behave equally to store.load()
File: src/data/Store.js
Line: 1545
Here is a workaround (extends Ext.data.Store):
Remember you have to handle the no-data situation yourself - i.e. listen to 'guaranteedrange'.Code:Ext.define('App.store.Store', { extend: 'Ext.data.Store', buffered: true, // -- fix the guaranteeRange() throwing exception on empty data set. onGuaranteedRange: function() { var me = this, totalCount = me.getTotalCount(), start = me.requestStart, end = ((totalCount - 1) < me.requestEnd) ? totalCount - 1 : me.requestEnd, range = [] ; if (start > end) { me.fireEvent('guaranteedrange', range, start, end); if (me.cb) { me.cb.call(me.scope || me, range); } me.unmask(); }else{ return this.callParent(arguments); } } });
-
11 Jul 2011 9:43 AM #25
Hey folks, I'm looking into this issue. My initial reaction is that making guaranteeRange public (and required for buffered loading) was probably not ideal to begin with. I'm inclined to say that as far as the public API of store goes, you should always call store.load() -- which in combination with a remote proxy already supports all of the necessary paging params -- and the whole business of guaranteeing ranges should be left as an internal store chore when buffering is needed. Unfortunately this would require API changes, so not sure exactly how I'm going to handle this for now, but I wanted to get feedback before I get started changing things.
Any reason I'm not thinking of that client code would actually want to guarantee that a range exists rather than just loading whatever happens to exist for a given page, buffering or no?
-
11 Jul 2011 10:39 AM #26
-
11 Jul 2011 11:14 AM #27Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Agreed, this whole paradigm is just wrong. I think we can provide a much better API in general for grids in 4.1 (while maintaining the existing one)
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
11 Jul 2011 11:23 AM #28
-
11 Jul 2011 12:25 PM #29Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Infinite scrolling DataView would be nice...
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
11 Jul 2011 12:26 PM #30
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
Similar Threads
-
[OPEN-EXTJSIV-555] Lost Selection in buffered grid.
By Luckyman in forum Ext:BugsReplies: 9Last Post: 28 Nov 2012, 3:00 AM -
[FIXED] Buffered Store with infinite grid - scrolling issues
By gctram in forum Ext:BugsReplies: 14Last Post: 8 May 2012, 6:32 AM -
[OPEN-EXTJSIV-207] Mixins issues
By LesJ in forum Ext:BugsReplies: 3Last Post: 21 Mar 2011, 12:58 PM -
[OPEN-EXTJSIV-205] Numeric axis issues
By vdan in forum Ext:BugsReplies: 1Last Post: 20 Mar 2011, 11:21 PM -
[OPEN-1226] Ext.data.Store and Ext.data.DataReader code and documentation issues
By timbonicus in forum Ext 3.x: BugsReplies: 1Last Post: 20 Aug 2010, 10:34 PM


Reply With Quote