PDA

View Full Version : How to prefetch local data into buffered store



Ex_Soft
23 Jul 2012, 5:48 AM
I'm trying work with buffered store and huge local data


Ext.onReady(function() {
var
createDataArray = function(max) {
var
data = [];

for(var i=0; i<max; ++i)
data.push( [ i, "Record# "+i ] );

return data;
},
store = Ext.create("Ext.data.Store", {
fields: [
{ name: "id", type: "int" },
"name"
],
buffered: true
}),
grid = Ext.create("Ext.grid.Panel", {
store: store,
columns: [
{ dataIndex: "id", header: "id" },
{ dataIndex: "name", header: "name" }
]
}),
w = Ext.create("Ext.window.Window", {
layout: "fit",
height: 200,
width: 300,
items: [grid]
});

store.loadData(createDataArray(10000));

w.show();
});

Store loads all data and grid renders all data. In 4.0.7 I used cacheRecords (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.Store-method-cacheRecords). But in 4.1.1 this method absents. How to prefetch local data?

scottmartin
23 Jul 2012, 6:47 AM
In 4.1, use cachePage()
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-cachePage

Scott.

Ex_Soft
23 Jul 2012, 10:59 AM
In 4.1, use cachePage()


Ext.onReady(function() {
Ext.define("TestModel", {
extend: "Ext.data.Model",
idProperty: "id",
fields: [
{ name: "id", type: "int" },
{ name: "name", type: "string" }
]
});

var
createDataJSON = function(max) {
var
data = [];

for(var i=0; i<max; ++i)
data.push( { id: i, name: "Record# "+i } );

return data;
},
store = Ext.create("Ext.data.Store", {
model: "TestModel",
buffered: true
}),
grid = Ext.create("Ext.grid.Panel", {
store: store,
columns: [
{ dataIndex: "id", header: "id" },
{ dataIndex: "name", header: "name" }
]
}),
w = Ext.create("Ext.window.Window", {
layout: "fit",
height: 200,
width: 700,
items: [grid]
}),
data = createDataJSON(10000),
records=[];

for(var i=0, len=data.length; i<len; ++i)
records.push(Ext.create("TestModel", data[i]));

store.cachePage(records /*, page ??? */);

w.show();
});

All records load into store.pageMap.first. How to adapt this (http://docs.sencha.com/ext-js/4-1/extjs-build/examples/grid/buffer-grid.js) 4.1.1 example for load local data such as 4.0.7 (http://docs.sencha.com/ext-js/4-0/extjs-build/examples/grid/buffer-grid.js)?

Ex_Soft
15 Aug 2012, 12:38 AM
Ext.onReady(function() {
Ext.define("TestModel", {
extend: "Ext.data.Model",
idProperty: "id",
fields: [
{ name: "id", type: "int" },
{ name: "name", type: "string" }
]
});

var
maxRecordsCount = 10000,
createDataJSON = function(max) {
var
data = [];

for(var i=0; i<max; ++i)
data.push( { id: i, name: "Record# "+i } );

return data;
},
store = Ext.create("Ext.data.Store", {
model: "TestModel",
buffered: true,
pageSize: maxRecordsCount,
proxy: {
type: "memory"
}
}),
grid = Ext.create("Ext.grid.Panel", {
store: store,
columns: [
{ dataIndex: "id", header: "id" },
{ dataIndex: "name", header: "name" }
]
}),
w = Ext.create("Ext.window.Window", {
layout: "fit",
height: 200,
width: 700,
items: [grid]
}),
data = createDataJSON(maxRecordsCount),
records=[];

for(var i=0, len=data.length; i<len; ++i)
records.push(Ext.create("TestModel", data[i]));

store.cachePage(records, 1);

w.show();
});

works