This plugin provides mathematical computations for complex expressions
This plugin provides formula computation on a DOM field. It Keeps watching, if any of the field (included in formula) changes it re-computes the formula.
To use this plugin, an attribute formula
need to be associated with the field on which the formula need to be computed.
<input type="text" placeholder="Auto-populated as formula" formula="$('#qty').value()*$('[name="pu"]').value()+$('#tax').value()-$('.disc').value()">
It can have complex jquery selectors like-
formula="$('#qty').value()*$('[name="pine"]').value()+$('.tax').value()-$('#disc').value()"
-
Row wise computation:
use
row
keyword to specify the current row. This plugin replacesrow
with$(this).closest(".last-data-row")
. So you have to havelast-data-row
class associated with each row. It can be written like-
formula="row.find('[name*="quantity"]').value()*row.find('[name*="price_per_unit"]').value()"
- Column wise computation:
For column wise computation this plugin uses aggregate functions like- sum, max, min, avg, count
formula="$('[name *= "tax_total"]').sum()"
formula="$('[name *= "tax_total"]').max()"
formula="$('[name *= "tax_total"]').min()"
formula="$('[name *= "tax_total"]').count()"
formula="$('[name *= "tax_total"]').avg()"
This function provides formula computation on the field(must have attribute formula
) on which it is fired. example-
$('container').find('[formula]').compute();
The formula will be recomputed if any formula dependency changes.
It is a wrapper on top of $.val()
, it takes care of NaN, undefined, ""
and parses the value in Float.
It loops over all the matched elements and returns their aggregated sum.
It loops over all the matched elements and returns the minimum value number.
It loops over all the matched elements and returns the maximum value number.
It returns the average of all matched element values.