-
26 Oct 2010 9:36 AM #1
Setting Store field value from other field values at load time
Setting Store field value from other field values at load time
Hi all,
I seem to recall an example that I've seen where a store field value or a grid column value was rendered by adding/subtracting two other fields at load time. I have tried all variations of search terms that I can think of but none of them has led me in the right direction so could someone please help me out?
Something like....
Thanks,PHP Code:var timeStore = new Ext.data.JsonStore({
url: '/gettime',
method: 'POST',
fields: [
{name: 'fromtime', type: 'date', dateFormat: 'H:i'},
{name: 'totime', type: 'date', dateFormat: 'H:i'},
{name: 'length', type: 'number', defaultValue:totime.replace(/:/,"")-fromtime.replace(/:/,"")}
]
});
G-Force
-
26 Oct 2010 10:26 AM #2
I got it working using the ColumnModel renderer like this:
Probably basic stuff for most and I'm sure the time subtraction can be more elegant but this does the job.PHP Code:{header: 'Length',
width:50,
dataIndex:'length',
renderer: function(value, metaData, record, rowIndex, colIndex, store) {
var mDiff = (parseInt(record.get('totime').dateFormat('H'))*60+parseInt(record.get('totime').dateFormat('i'))-(parseInt(record.get('fromtime').dateFormat('H'))*60+parseInt(record.get('fromtime').dateFormat('i'));
var sign = (mDiff<0?'-':'');
mDiff = Math.abs(mDiff);
var hDiff = Math.floor(mDiff/60);
mDiff = mDiff % 60;
return sign+(hDiff<10?'0':'')+hDiff+':'+(mDiff<10?'0':'')+mDiff;
}
}
Thanks,
G-Force
Similar Threads
-
setting field label and field type based on XML value
By brikonwall in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 18 Mar 2008, 7:16 PM -
Let Store.load wait for results, setting (ComboBox) display values in grid
By lvanderree in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 14 Oct 2007, 4:00 PM -
Setting field properties automatically on form load
By HartlepoolLad in forum Ext 1.x: Help & DiscussionReplies: 0Last Post: 31 Jul 2007, 2:54 AM


Reply With Quote