the method called for cells with math calculations to define math rendering in such cells
The method is not intended for direct calls.
The $mathTemplate function takes the following parameters:
=A11If you need to control what a cell returns when referenced (like with a checkbox that returns it's state, not the checkbox HTML), you can customize $mathTemplate.
For example, if a cell contains a button, you can specify that the result of the math calculation in it will return button HTML:
const spreadsheet = webix.ui({view:"spreadsheet"});
spreadsheet.$$("cells").on_click["webix_button"] = function(ev, cell){
webix.message(`Button click in cell ${spreadsheet.posToRef(cell.row, cell.column)}`);
};
const defaultMathTemplate = spreadsheet.$mathTemplate;
spreadsheet.$mathTemplate = function(math, value){
let val = defaultMathTemplate.apply(this, arguments);
if(/^=button\(/i.test(math))
return "<input class='webix_button' type='button' value='click me!'>";
return val;
}
spreadsheet.registerMathMethod("BUTTON", ()=> "My button", null, true);
// if another cell references this cell, it will receive "My button"
spreadsheet.setCellValue(1, 1, "=BUTTON()");
// returns text "My button" instead of button html
spreadsheet.setCellValue(2, 1, "=A1");
Otherwise, you can simply set what the cell returns directly in registerMathMethod() (without customizing $mathTemplate):
spreadsheet.registerMathMethod(
"BUTTON",
()=> "<input class='webix_button' type='button' value='click me!'>",
null,
true
);
Back to top