NEW VERSION RELEASED! Webix 11 Read More Core Updates, Extended Functionalities in SpreadSheet and File Manager and more

Custom Math Methods, JavaScript Programming Example of Custom Math Methods in SpreadSheet

JavaScript Programming Example of Custom Math Methods in SpreadSheet

The programming example below allows defining custom math methods in SpreadSheet. Take into account that this piece of code is free. Don't miss out on the chance to use the coding samples by Webix for your web development projects.

JS Code

webix.ui({
  view:"spreadsheet",
  id:"ss",
  toolbar: "full",
});

$$("ss").registerMathMethod("RANDOM", function(value){
  value = value || 100;
  return Math.round(Math.random()*value);
});
$$("ss").registerMathMethod("FIRST", function(set){
  return set[0];
});
$$("ss").registerMathMethod("LAST", function(set){
  return set[set.length-1];
});

$$("ss").parse({
  data:[
    [2,2,"RANDOM"], [2,3,"FIRST"], [2,4,"LAST"],
    [3,2,"=RANDOM(1000)"], [3,3,"=FIRST(F2:F4)"], [3,4,"=LAST(F2:F4)"],
    [2,6,"1"],[3,6,"2"],[4,6,"3"]
  ]
});