$mathTemplate

the method called for cells with math calculations to define math rendering in such cells

function $mathTemplate;
Details

The method is not intended for direct calls.

The $mathTemplate function takes the following parameters:

  • math - the math in the cell, e.g. =A1
  • value - the result of calculations, e.g. 1

If 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
Join Our Forum
We've retired comments here. Visit our forum for faster technical support, connect with other developers, and share your feedback there.