ejCalculate

Custom engine to perform calculation like excel sheet
$(element).ejCalculate()
Example

  • html
  • <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
  • html
  • FormulaName
    string pass the formula name
  • html
  • FunctionName
    string pass the custom function name to call

    Example

  • html
  • <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
  • html
  • Name
    string pass the namedRange's name
  • html
  • cellRange
    string pass the cell range of NamedRange

    Example

  • html
  • <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
  • html
  • Name
    string pass the cell range to adjust its range

    Returns:

    string

    Example

  • html
  • 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
  • html
  • Cell
    string pass the changed cell address

    Example

  • html
  • 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

  • html
  • 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
  • html
  • Cell
    string pass the cell address

    Example

  • html
  • var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
    calcObj.colIndex("A1");
    </script>

    computedValue(Formula)

    Evaluates a parsed formula.

    Name Type Description
  • html
  • Formula
    string pass the parsed formula

    Returns:

    string

    Example

  • html
  • var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
    calcObj.computedValue("&rsquo;n10n2a&rsquo;");
    </script>

    computeFormula(Formula)

    Evaluates a parsed formula.

    Name Type Description
  • html
  • Formula
    string pass the parsed formula

    Returns:

    string

    Example

  • html
  • var calcObj = new CalcEngine($("#Grid").data("ejGrid"));
    calcObj.computedValue("&rsquo;n10n2a&rsquo;");
    </script>