PDA

View Full Version : how do i change totalProperty count before data store load



brumble
24 Apr 2007, 7:38 PM
hi guys, may i know how do i change the count of totalProperty before the datastore load?

my method which is not right:

ds.on('beforeLoad', function(){
function setParams(start, limit, sort, dir){
var params = {}, map = this.paramMap;

ds.reader.totalProperty = (threaded.selectedIndex < 2) ? 'Messages.firstCnt' : 'Messages.secondCnt';

params['page'] = paging.getPageData().activePage;
params['rows'] = paging.pageSize;
params['sortfield'] = (sort == 'dateCol') ? 'date' : sort;
params['sortorder'] = (dir == 'ASC') ? '1' : '0';
return params;
};
ds.baseParams = setParams();
});

the old method thats working:

dm.createParams = function(pageNum, sortColumn, sortDir){
var params = {}, map = this.paramMap;
for(var key in this.baseParams){
if(typeof this.baseParams[key] != 'function'){
params[key] = this.baseParams[key];
}
}

this.schema.totalProperty = (threaded.selectedIndex < 2) ? 'Messages.firstCnt' : 'Messages.secondCnt';

params['page'] = pageNum;
params['rows'] = this.getPageSize();
params['sortfield'] = (sortColumn == 8) ? 'date' : this.schema.fields[sortColumn];
params['sortorder'] = (sortDir == 'ASC') ? '1' : '0';

return params;
};

hope you guys could highlight to me whats wrong, thanks!

Animal
24 Apr 2007, 11:32 PM
You want to change the count that the Store has of the number of Records to be different from what it actually received from the server?



myStore.totalLength = n;


In a "load" handler function.

Animal
24 Apr 2007, 11:41 PM
Ah, you don't want to change the count, you want to change the property name!

It's



myReader.meta.totalProperty = "totalRecs";


You must be using a JsonReader for it to be using the totalProperty property name in its config.

Be aware that JsonReaders, the first time they read a record, generate extraction functions to pull out the various properties they need from the response data object. So once generated, the extraction function to pull the record count out of the object will always pull the same property.

To force a JsonReader to recalculate the extraction functions according to any new property names you poke into the "meta" property, use



delete myJsonReader.ef;


With an XmlReader, you can change the "totalRecords" property any time, and it will use that in a DomQuery select on each read, so this won't be needed.

brumble
25 Apr 2007, 1:48 AM
sorry i didn't stated clearly what i'm doing. i actually have a json file which return me a firstCnt, secondCnt and a list of messages.

actually i need to do a check if user selected threading, the value of totalProperty would be set to firstCnt and if no threading is selected, the value of totalProperty would be set to secondCnt:


ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'js/msg/getMsgs.aspx?msgId=1&out=json'}),
reader: new Ext.data.JsonReader({
root: 'Messages',
totalProperty: 'Messages.firstCnt',
id: 'msgId'},
[{name: 'msgDate', mapping: 'dtMsgDate_Display'},
{name: 'id', mapping: 'msgID'},
{name: 'title', mapping: 'msgTitle'},
{name: 'status', mapping: 'msgStatus'},
{name: 'myInfo', mapping: 'msgInfo'}]),
remoteSort: true
});

i did something like this to change my value for totalProperty:


ds.on(beforeLoad, function(){
ds.baseParams = getMyParams(); //return a list of params
ds.reader.meta.totalProperty = (threading.selectedIndex < 2) ? 'Messages.firstCnt' : 'Messages.secondCnt';
}

i hope i have made things clearer now.. however it seems like it isn't working..

brumble
25 Apr 2007, 2:09 AM
thank you Animal, i manage to change the value of totalProperty correctly now:


ds.on(beforeLoad, function(){
ds.baseParams = getMyParams(); //return a list of params
delete this.reader.ef;
ds.reader.meta.totalProperty = (threading.selectedIndex < 2) ? 'Messages.firstCnt' : 'Messages.secondCnt';
}

now my JsonReader recalculate the extraction functions. thanks for your advise! :)