View Full Version : EXT 4.2 : perform Math operations +-*/% in Ext.XTemplate on two data fields

23 May 2014, 1:46 AM
My Model:

Ext.define('paymentModel', { extend: 'Ext.data.Model', fields: [ 'totalPayment', 'targetCost','itemCount', { name: 'totalPayment', type: 'number', }, { name: 'claimsCount', type: 'number' }, { name: 'targetCost', type: 'number' } ]});

Template i want to write

var tpl = new Ext.XTemplate( '<TABLE width="100%" cellpadding=4 style="margin-top: 10px">', '<TR><TD>Payment Amount</TD><TD>Average/Claim</TD></TR>', '<TR class="ppm-result-value"><TD>{totalPayment}</TD><TD> {totalPayment/claimsCount}</TD></TR>', '<TR><TD>SOURCE</TD><TD>SOURCE</TD></TR>', '<TR class="ppm-result-value"><TD>{targetCost}</TD><TD>{targetCost/1000}</TD></TR>', '</TABLE>' );

Question :
{targetCost/1000} is calculated (also e.g given in sencha docs).
how can i compute {totalPayment/claimsCount} and {totalPayment%claimsCount} in XTemplate.
I am new to extjs and trying out few things for my project.
I have gone throught he sencha documentation , but could not figure out the right way to get this work.
Seeking help from experienced Ext developers. My apologies if its answered in other threads ,
i searched and got no solution.

23 May 2014, 6:47 AM
Here is a fiddle that displays calc functions in a template:

29 May 2014, 10:36 AM
Thanks you so much for quick reply , the solution worked gr8.