PDA

View Full Version : extjs4.0.7 store prefetch get raw data



timTaylor
18 Jul 2012, 5:40 AM
my store ( 'this._store ' because it's a member of a class)



// store setup ...
var reader = Ext.create('Ext.data.reader.Json',
{
root :'data[0].myDataArr',
totalProperty:'data[0].totalcount'
});
var proxy = Ext.create('Ext.data.proxy.Ajax',
{
url :'~myUrl~',
simpleSortMode:true,
reader :reader
});
this._store = Ext.create('Ext.data.Store', {
model :'myModel',
remoteSort:true,
buffered :true,
proxy :proxy,
pageSize :100
});

// add listener to the store ...
this._store.on('beforeprefetch',function(theStore, dataOperation, eOpts)
{

var reader = scope._store.proxy.reader;
console.log('reader',reader);
// ****************************************************
// at this moment, the reader doesn't contain the member 'rawData' ????
// but I need access to the rawData, because it contains important
// data I've built up server-side(as you can see at the trace inside the
// PrefetchStore function)
// the log:
// reader
// Ext.Class.newClass
// extractorFunctions: Array[17]
// fieldCount: 17
// fireEvent: function () {
// getId: function (record) {
// getRoot: function anonymous(obj) {
// getSuccess: function (obj) {
// getTotal: function anonymous(obj) {
// model: function () {
// root: "data[0].myDataArr"
// totalProperty: "data[0].totalcount"
// __proto__: Class.registerPreprocessor.prototype
// ****************************************************
});
// load store ...
this.PrefetchStore(new Array());

the prefetch-function:


PrefetchStore:function (filterArr)
{
var scope = this;

var grid = Ext.getCmp('mygrid');
store = this._store;
// Clear out prefetched and loaded data
store.prefetchData.clear();
store.removeAll();
// This is very important - set it back to it's original state
delete store.guaranteedStart;
delete store.guaranteedEnd;
// Remove this as well - or else you'll get an unwanted side effect when you reload the grid that previously had a dataset smaller than pageCount
delete store.totalCount;
// start prefetching
this._store.prefetch({
start :0,
limit :100,
remoteFilter:true,
filters :filterArr,

callback :function (resArr, theStore)
{
// totalcountUnlimited holds the unlimited SQL-result numRows
var count = scope._store.proxy.reader.rawData.data[0].totalcountUnlimited;

console.log('scope._store.proxy.reader.',scope._store.proxy.reader);
// *************************************************
// traces:
//
// scope._store.proxy.reader.
// Ext.Class.newClass
// extractorFunctions: Array[17]
// fieldCount: 17
// fireEvent: function () {
// getId: function (record) {
// getRoot: function anonymous(obj) {
// getSuccess: function (obj) {
// getTotal: function anonymous(obj) {
// jsonData: Object
// model: function () {
// rawData: Object
// cXerrorArr: Array[0]
// data: Array[1]
// errorMsgStr: ""
// html: ""
// javascript: ""
// logMsgArr: Array[9]
// success: true
// __proto__: Object
// root: "data[0].myDataArr"
// totalProperty: "data[0].totalcount"
// __proto__: Class.registerPreprocessor.prototype
// *************************************************

scope._filterPanel.setTitle('@filters@ [' + count + ' @entries@]');
if( count ) scope._store.guaranteeRange(0, scope._store.pageSize - 1);
}
});
}