Dynamically generating a custom function, Custom function autocomplete

Posted by: smorosow.dev on 22 June 2022, 4:03 am EST

  • Posted 22 June 2022, 4:03 am EST

    Hi there,

    I'm evaluating SpreadJS and I have 2 questions regarding custom functions:

    1. Can you provide an example of how to generate a custom function dynamically via code? For example if I get a list of function names and operations from a DB how can I turn them into custom function in SpreadJS? I tried creating a custom function factory but it didn't seem to work.

    2. I noticed that in the Custom Functions demo that the custom functions do not appear in the auto-complete list (for example when typing "=" in a cell) like the built-in ones do. Is there a way to make them discoverable in the autocomplete?

    Thanks
  • Replied 22 June 2022, 4:07 am EST

    To clarify, my first question is how can I get a custom function generator to which I can call
    myCustomFunc = createFunction({name: 'MY_CUSTOM_FUNC', minArgs: 1, maxArgs: 1, evaluate: (arg) => `The arg was ${arg}`})
  • Replied 22 June 2022, 6:19 pm EST

    Hi,

    You can use the Function type that represents an abstract base class for defining function. Then add the Custom Function to the workbook.

    You can refer to the following sample that I have created for you: https://jscodemine.grapecity.com/share/w_PtGzWHeE6pXOqA97lJMA/

    addCustomFunction Method: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.Workbook~addCustomFunction.html

    Function Type: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.CalcEngine.Functions.Function.html

    I hope this resolves your issue. Please let us know if you need further assistance on this. We would be happy to help you.

    Regards

    Ankit
  • Marked as Answer

    Replied 22 June 2022, 6:46 pm EST

    Thanks. Your example above works well. I tried the same exact thing yesterday in the custom functions codemine and it had the 2 issues I mentioned but if it works otherwise than that's fine.

Need extra support?

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

Learn More

Forum Channels