SpreadJS 14
Formula Reference / Formula Functions / Other Functions / REFRESH
In This Topic
    REFRESH
    In This Topic

    This function recalculates the formula reference.

    Syntax

    REFRESH(formula, evaluateMode, interval)

    Arguments

    This function has these arguments:

    Argument Description
    formula A reference to the formula to evaluate. This argument is required.
    evaluateMode The GC.Spread.CalcEngine.Functions.AsyncFunctionEvaluateMode type. This argument is required.
    interval The interval in milliseconds. The evaluateMode option must be set to interval to use this option.

    Remarks

    Use REFRESH when you want to control how formulas recalculate.

    Example

    sheet.setFormula(2, 2, "=Refresh(now(), 2, 1000)");

    sheet.setFormula(3, 2, "=REFRESH(GETTIMEFROMSERVER(),1)");

    Using Code

    This example uses the REFRESH formula.

    JavaScript
    Copy Code
    <!DOCTYPE html>
    <html>
    <head>
        <title>SpreadJS</title>
    <link href="./css/gc.spread.sheets.13.0.0.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="./scripts/gc.spread.sheets.all.13.0.0.min.js"></script>
    <!--jQuery References-->
    <script src="http://code.jquery.com/jquery-2.0.2.js" type="text/javascript"></script>
      <script type="text/javascript">
             window.onload = function () {
         var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 3});
         var sheet = spread.getActiveSheet();
         var GetNumberFromServer = function () {
         }
         GetNumberFromServer.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("GETNUMBERFROMSERVER", 2, 2);
         GetNumberFromServer.prototype.evaluate = function () {
             var context = arguments[0], arg1 = arguments[1];
             $.get('http://domain_name/api/dir/ ' + (arg1 || 1), function (value) {
                 context.setAsyncResult(value);
             });
         }
     
         var GetTimeFromServer = function () {
         }
         GetTimeFromServer.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("GETTIMEFROMSERVER", 2, 2);
         GetTimeFromServer.prototype.evaluate = function (context) {
             $.get('http://domain_name/api/time/ ', function (value) {
                 context.setAsyncResult(value);
             });
         }
         GetTimeFromServer.prototype.evaluateMode = function () {
             return 2;
         };
         GetTimeFromServer.prototype.interval = function () {
             return 1000;
         };
     
         GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETNUMBERFROMSERVER", new GetNumberFromServer());
         GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEFROMSERVER", new GetTimeFromServer());
     
         sheet.setValue(0, 0, 'ChangeValue');
         sheet.setValue(0, 1, 'Formula');
         sheet.setValue(0, 2, 'Result');
         sheet.setValue(0, 3, 'Comments');
         sheet.setValue(1, 3, 'On A2 changed');
         sheet.setValue(2, 3, 'On A2 changed');
         sheet.setValue(3, 3, 'Evaluate once');
         sheet.setValue(4, 3, 'Every 2 seconds');
         sheet.setValue(1, 0, 1);
         sheet.setValue(1, 1, '=GetNumberFromServer(A2)');
         sheet.setValue(2, 1, '=Refresh(GetNumberFromServer(A2), 0)');
         sheet.setValue(3, 1, '=Refresh(GetNumberFromServer(A2), 1)');
         sheet.setValue(4, 1, '=Refresh(GetNumberFromServer(A2), 2, 2000)');
         sheet.setFormula(1, 2, '=GetNumberFromServer(A2)');
         sheet.setFormula(2, 2, '=Refresh(GetNumberFromServer(A2), 0)');
         sheet.setFormula(3, 2, '=Refresh(GetNumberFromServer(A2), 1)');
         sheet.setFormula(4, 2, '=Refresh(GetNumberFromServer(A2), 2, 2000)');
         sheet.setColumnWidth(0, 100);
         sheet.setColumnWidth(1, 300);
         sheet.setColumnWidth(2, 200);
         sheet.setColumnWidth(3, 200);
     
         sheet.setValue(7, 1, "=Refresh(now(), 2, 1000)");
         sheet.setValue(7, 3, "Every 1 seconds");
         sheet.setFormula(7, 2, "=Refresh(now(), 2, 1000)");
     
         sheet.setValue(10, 1, "=GetTimeFromServer()");
         sheet.setValue(10, 3, "Every 1 seconds");
         sheet.setFormula(10, 2, "=GetTimeFromServer()");
         sheet.getCell(10, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
     }                                      
    </script>
    
    </head>
    <body>
        <div id="ss" style="width:100%;height:500px;border:1px solid gray"></div>
    </body>
    </html>