View Full Version : Override/Extend model field

1 Jul 2013, 10:13 PM

Is it possible to extend/override a model field value? i.e. If I create a field named "TotalCost" which is in fact needs to be computed eg. Quantity * Hours * Rate then the TotalCost field should return something like

Ext.define('My.Model', {
extend: 'Ext.data.Model',
TotalCost: function(){
return this.get('Rate') * this.get('Hours') * this.get('Quantity');

I know this is in correct because I need to override the TotalCost getter function? But how do I do this?

There is a reason in doing it this way rather than using a renderer. Im using a treepanel and need to sum child records and it will be easier just to call the record.get('TotalCost') rather than have to compute all the time?

Thanks for any advice?

1 Jul 2013, 10:35 PM
just create a field called 'totalcost' in your model and use the convert() function to return the value as this function gives you the record to work with.

2 Jul 2013, 1:26 PM
Excellent. Exactly what I was looking for.

Thank you!