Custom Function Parameter Description

Posted by: cory.engel on 14 November 2023, 3:19 pm EST

    • Post Options:
    • Link

    Posted 14 November 2023, 3:19 pm EST - Updated 14 November 2023, 3:24 pm EST

    When creating custom functions, we’d like to include descriptions of the function parameters. For example, with the FACTORIAL example function, we have code (Vue3) such as:

    customFormulas() {
          // allow dynamic array
          this.spread.options.allowDynamicArray = true;
          // create a factorial function
          function FactorialFunction() {
            this.name = 'FACTORIAL';
            this.maxArgs = 1;
            this.minArgs = 1;
          }
          FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
          //evaluating the result of the formula
          FactorialFunction.prototype.evaluate = function (arg) {
            var result = 1;
            if (arguments.length === 1 && !isNaN(parseInt(arg))) {
              for (var i = 1; i <= arg; i++) {
                result = i * result;
              }
              return result;
            }
            return '#VALUE!';
          };
          //Adding a description to the custom Function
          FactorialFunction.prototype.description = function () {
            return {
              name: 'FACTORIAL',
              description: 'This is function which calculates the factorial from 1 and show in different cells of a row'
            };
          };
          var factorial = new FactorialFunction();
          this.spread.addCustomFunction(factorial);
        }

    How can we set the parameter description to ‘number’ for example, to show in the formula popup?

  • Posted 15 November 2023, 3:25 am EST

    I found the api docs that explain it. Thanks.

  • Posted 15 November 2023, 3:32 pm EST

    Hi,

    We are glad that your issue has been resolved.

    You can specify the parameter description with the IFunctionDescription interface and function.description() method. You may refer to https://developer.mescius.com/spreadjs/api/interfaces/GC.Spread.CalcEngine.Functions.IFunctionDescription#parameters to learn more about them.

    Regards

Need extra support?

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

Learn More

Forum Channels