Overwriting a built-in function

Posted by: daniel on 9 April 2019, 1:26 pm EST

    • Post Options:
    • Link

    Posted 9 April 2019, 1:26 pm EST

    In SpreadJS is it possible to overwrite a built-in, Excel-like function?

    For example, are the following use cases possible?

    1. Modify the SUM function execution so that, for example, it concatenates the parameter values?
    2. Modify the SUM function to take in a JSON variable as a parameter. E.g.,

      SUM({revenueOne: 1000, revenueTwo: 5000})

    Thank you!

    Daniel

  • Posted 10 April 2019, 6:13 am EST

    Hi,

    We could override the default formula in the following two steps:

    1). Remove the existing definition of the formula like:

    GC.Spread.CalcEngine.Functions.removeGlobalFunction('sum');```
    
    
    2). Add custom function with the same name using addCustomFunction method
    

    var customFun = new CustomSumFunction();

    spread.addCustomFunction(customFun);

    
    [i]>>Modify the SUM function to take in a JSON variable as a parameter.[/i]
    Formulas don't support passing JSON values as parameters, what we could do is pass a string which would represent our JSON and then parse the string inside our custom function to get the JSON.
    Please refer to the attached sample which demonstrates the same and let us know if you face any issues.
    
    Regards
    [zip filename="customFunctions.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-82ba956c-eee9-4f7d-b69a-cf5a51d418d3.zip[/zip]
  • Posted 10 April 2019, 11:25 am EST

    Very useful answer - thank you so much!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels