Customize Function

Customize functions in C#

Add customize function to extend control:
grid.Srm["sqrt"] = new NativeFunctionObject("sqrt", (ctx, owner, args) =>
{
    if (args.Length < 1)
        return NaNValue.Value;
    else
        return Math.Sqrt(ScriptRunningMachine.GetDoubleValue(args[0], 0));
});
Test:
grid[2, 1] = "=sqrt(400)";

44.png
View its formula:
43.png

Customize function is also can used in script.

Customize functions in Script

Object 'script' is the global object which is available in both formula and script. (same as 'window' in JavaScript)
45.png
Run the code above once and use it in formula.
46.png
Press 'enter':
47.png

Run Script to add functions in C#

It is also possible to run the script to create functions in C#: (eg. lambda function)
grid.RunScript("script.myfunc = data => '[' + data + ']';");

Next: Custom Cell

Last edited Feb 16, 2014 at 3:07 PM by unvell, version 12