ejCalculate
18 Oct 2016 / 4 minutes to read
Custom engine to perform calculation like excel sheet
$(element).ejCalculate()
Example
<script>
// Create calcEngine with grid data
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
</script>
Requires
-
module:jQuery
-
module:ej.core.js
-
module:ej.calculate.js
Methods
addCustomFunction(FormulaName, FunctionName)
Add the custom formulas with function in CalcEngine library
Name | Type | Description |
---|---|---|
|
string | pass the formula name |
|
string | pass the custom function name to call |
Example
<div id="Grid"></div>
<script>
// Create Grid
$('#Grid').ejGrid({
dataSource: window.gridData
});
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
var sheetID = calcObj.createSheetFamilyID();
calcObj.registerGridAsSheet("sheet1", $("#Grid").data("ejGrid"), sheetID);
calcObj.addCustomFunction("ADD", "customAdd");
customAdd = function (argsList) {
var splitArgs = argsList.split(calcObj.getParseArgumentSeparator())
var result = 0;
for (var i in splitArgs) {
var s1 = calcObj.getValueFromArg(splitArgs[i]);
result = Number(result) + Number(s1);
}
return result;
}
</script>
addNamedRange(Name, cellRange)
Adds a named range to the NamedRanges collection
Name | Type | Description |
---|---|---|
|
string | pass the namedRange's name |
|
string | pass the cell range of NamedRange |
Example
<div id="Grid"></div>
<script>
// Create Grid
$('#Grid').ejGrid({
dataSource: window.gridData
});
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
var sheetID = calcObj.createSheetFamilyID();
calcObj.registerGridAsSheet("sheet1", $("#Grid").data("ejGrid"), sheetID);
calcObj.addNamedRange("FIRSTCELL","A1");
</script>
adjustRangeArg(Name)
Accepts a possible parsed formula and returns the calculated value without quotes.
Name | Type | Description |
---|---|---|
|
string | pass the cell range to adjust its range |
Returns:
string
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
var sheetID = calcObj.createSheetFamilyID();
calcObj.registerGridAsSheet("sheet1", $("#Grid").data("ejGrid"), sheetID);
calcObj.addNamedRange("FIRSTCELL","A1");
</script>
clearFormulaDependentCells(Cell)
When a formula cell changes, call this method to clear it from its dependent cells.
Name | Type | Description |
---|---|---|
|
string | pass the changed cell address |
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
calcObj.clearFormulaDependentCells("A1");
</script>
clearLibraryComputationException()
Call this method to clear whether an exception was raised during the computation of a library function.
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
calcObj.clearLibraryComputationException();
</script>
colIndex(Cell)
Get the column index from a cell reference passed in.
Name | Type | Description |
---|---|---|
|
string | pass the cell address |
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
calcObj.colIndex("A1");
</script>
computedValue(Formula)
Evaluates a parsed formula.
Name | Type | Description |
---|---|---|
|
string | pass the parsed formula |
Returns:
string
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
calcObj.computedValue("’n10n2a’");
</script>
computeFormula(Formula)
Evaluates a parsed formula.
Name | Type | Description |
---|---|---|
|
string | pass the parsed formula |
Returns:
string
Example
var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
calcObj.computedValue("’n10n2a’");
</script>
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page