PDA

View Full Version : problem including timestamp for lastest auto refresh



mohteshim
1 Jul 2007, 5:29 AM
Hi ppl,
In need of help.... can you please guide me with a timestamp, which i want to use, so that when the xml refreshes it checks against the timestamp and if there is new data then it refreshes, otherwise leave the existing xml file intact.

below is my xml code...
the problem is that i am unable to copy the value of 'timestamp' (marked in read in the code below) to the local variable ts. your help will be very much appriciated.

where am i going wrong

thnks & rgds
Mo


/*
* Ext JS Library 1.1 Beta 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* [email protected]
*
* http://www.extjs.com/license
*/
var ts=1;
//var callback = 'setTS()';


Ext.onReady(function(){

// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'gridXml.php'}),

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'Item',
id: 'id',
ts: 'timestamp',
fields: ['OrderID', 'customer_id', 'market_ticket_id', 'fullname', 'buysell', 'status', 'symbol', 'quantity', 'price', 'timestamp']
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'OrderID', mapping: 'ItemAttributes > OrderID'},
'customer_id', 'market_ticket_id', 'fullname', 'buysell', 'status', 'symbol', 'quantity', 'price', 'timestamp'
])
});

//alert( ds.reader.record );


// example of custom renderer function
function italic(value){
return '<i>' + value + '</i>';
}

/*function updateTS(value)
{
ts = value;
return true;
}*/
// example of custom renderer function
function change(val){
var str = new String( val );
str = str.toLowerCase();

if(str == "buy"){
return '<span style="color:#0000FF;">' + val + '</span>';
}else if(str == "sell"){
return '<span style="color:#FF0000;">' + val + '</span>';
}
return val;
}

// example of custom renderer function
function statusc(val){
var str = new String( val );
str = str.toLowerCase();

if(str == "completed"){
return '<span style="color:green;">' + val + '</span>';
}else if(str == "sell"){
return '<span style="color:#FF0000;">' + val + '</span>';
}
return val;
}
// example of custom renderer function
function pctChange(val){
return '<span style="align:right;">' + val + '</span>';
}

var cm = new Ext.grid.ColumnModel([
{header: "Order ID", width: 80, dataIndex: 'OrderID'},
{header: "Customer ID", width: 100, dataIndex: 'customer_id'},
{header: "Ticket ID", width: 100, dataIndex: 'market_ticket_id'},
{header: "Name", width: 200, dataIndex: 'fullname'},
{header: "Type", width: 50, renderer: change, dataIndex: 'buysell'},
{header: "Status", width: 100,renderer: statusc, dataIndex: 'status'},
{header: "Symbol", width: 100, dataIndex: 'symbol'},
{header: "Quantity", width: 100, renderer: pctChange, dataIndex: 'quantity'},
{header: "Price", width: 100, dataIndex: 'price'},
{header: "Timestamp", width: 100, dataIndex:'timestamp', hidden:false}
]);
cm.defaultSortable = true;

// function for auto refreshing the xmml data feed
Ext.override(Ext.data.Store, {
startAutoRefresh : function(interval, params, callback, refreshNow){
if(refreshNow){
this.load({params:params, callback:callback});
}
if(this.autoRefreshProcId){
clearInterval(this.autoRefreshProcId);
}
this.autoRefreshProcId = setInterval(this.load.createDelegate(this, [{params:params, callback:callback}]), interval*1000);
}
});

//all_pending:false, timestamp:ts, associated_broker_user_id_filter:-1, broker_user_id_filter:-1, cancelled_check:false, completed_check:true, customer_id:3, end_day:1, end_month:6, end_year:2007, executed_broker_user_id_filter:-1, expired_check:false, filled_broker_user_id_filter:-1, group_id: , lang_id:1, order_id:0, orderby:0, pending_check:true, rejected_check:false, selected_market:0, start_day:24, start_month:5, start_year:2007, user_id:3, view_simulated:1

ds.startAutoRefresh(5, {limit:25, start:0, all_pending:false, associated_broker_user_id_filter:-1, broker_user_id_filter:-1, cancelled_check:false, completed_check:false, customer_id:21395, end_day:1, end_month:6, end_year:2007, executed_broker_user_id_filter:-1, expired_check:false, filled_broker_user_id_filter:-1, group_id:0 , lang_id:1, order_id:0, orderby:0, pending_check:true, rejected_check:false, selected_market:0, start_day:1, start_month:6, start_year:2007, user_id:21395, view_simulated:1 });

// create the grid
var grid = new Ext.grid.Grid('example-grid', {
ds: ds,
cm: cm

});
grid.render();

ds.load();
});