registerMathMethod

добавление новой формулы

void registerMathMethod(string name,function handler,string category,boolean generateHTML);
namestringназвание формулы (буквами в верхнем регистре)
handlerfunctionобработчик, который определяет логику работы формулы
categorystringoptional, the name of a custom category for a new math method
generateHTMLbooleanoptional, allows a custom method to generate HTML, while the xssSafe property is enabled

Example

$$("ss1").registerMathMethod("NEW", function(value){
    // ваш обработчик
});

Related samples

Details

Функция-обработчик может получать параметры, например значение одной ячейки, значения из диапазона ячеек (значения будут передаваться по ссылкам, например H3 или H3:H5) или произвольные параметры (например, число знаков после запятой, до которого нужно округлить число).

Новую формулу можно использовать как обычную встроенную функцию: =NEW(H3:H5);.

Вы можете добавить подсказки для параметров новой формулы, обновив локаль webix.i18n.spreadsheet.liveEditor["functions-syntax"].

Например:

const ssheet = webix.ui({
  view: "spreadsheet",
  toolbar: "full"
});
 
ssheet.registerMathMethod("RANDOM", function(value){   value = value || 100;    return Math.round(Math.random()*value); });   
webix.i18n.spreadsheet.liveEditor["functions-syntax"].RANDOM = [      ["Digit", "Optional. The number digit."]  ];   
ssheet.setCellValue(1,1,"=RANDOM(100)")

It is also possible to specify a custom category while adding a new math method:

webix.ui({
  view:"spreadsheet",
  id: "sheets",
  methods:"all",
  toolbar:"full",
}); 
 
webix.i18n.spreadsheet.liveEditor.custom = "Custom";
$$("sheets").registerMathMethod("returnone", () => 1, "custom");
$$("sheets").setCellValue(1, 1, "=RETURNONE()")

If you need to allow a custom method to generate HTML, while the xssSafe property is enabled, set the generateHTML parameter of the registerMathMethod() method to true. Check the example below:

const spreadsheet = webix.ui({
    view: "spreadsheet",
    xssSafe: true
});
 
spreadsheet.registerMathMethod("bold", v => `<b>${v}</b>`, null, true);
spreadsheet.setCellValue(1, 1, '=bold("text")');

Note that while using the method with allowed HTML generation in math formulas, you should specify only the method in the formula. For example: =IMAGE(...) will generate an image, but =IMAGE(...)&"text" will be escaped.

See also
Наверх
If you have not checked yet, be sure to visit site of our main product Webix ui component library and page of spreadsheet product.