Threaded View
-
19 May 2011 7:56 AM #19
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!
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