PDA

View Full Version : Store data load : cyclic append (add parameter not working)



joseph.piron
3 Apr 2012, 2:18 AM
Hi guys,
everything's going on great with this first big extjs app, very exciting :)

But, ... I got a problem:
I am trying to have a dynamic data update of a graph which get values from ajax calls.
The problem is that I would like to fetch only new records from server (setting an 'after' parameter by hooking up the beforeload event) and add them to already displayed data (after I will remove excessive data). Reading the doc, I believe I should add a {add:true} as parameter for the load call triggered by Ext.TaskManager every minutes or so.
Unfortunately, it doesn't work, when there are new records, previous ones are removed and the totalCount of the store is set to the number of fetched records. I also tried with a 'append' parameter but nothing fancier.

Is this not how I should use this parameter ?

Thanks in advance !

ps: some code to figure out:


var s = Ext.create("Ext.data.Store", { fields:["timeStamp", this.node.get('alias')],
pageSize:400,
proxy:{
type:"rest", // .... mouais
url:'/webmoni/default/values.json',
reader:{
type:'json',
root:'result'
},
extraParams:{
aliases:[this.node.parentNode.get('id') + ',' + this.node.get('alias')]
}
},
listeners:{
beforeload:function (store, op, opt) {
// if (!this.totalCount) {
// var after = new Date().addHours(-1).toString("yyyy-MM-dd H:m:s");
// }
// else {
// var after = new Date(this.last().get('timeStamp')).toString("yyyy-MM-dd H:m:s");
// }
// store.getProxy().extraParams.after = after;
//TODOO: refresh only last points
store.getProxy().extraParams.after = new Date().addHours(-1).toString("yyyy-MM-dd H:m:s");
},


load:function (store, op) {
console.log(this.totalCount);
}
}
});

and a bit after:


this.updateTask = Ext.TaskManager.start({ store:this.store,
run:function () {
this.store.load({ add:true, append:true});
},
interval:1000*60
})

mitchellsimoens
3 Apr 2012, 11:41 AM
You can use addRecords but this will simply add the new records in, not check if they are existing.

joseph.piron
17 Apr 2012, 3:28 AM
no way to have a live update then ?
Is the add/append parameter not intended for this ?