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.ready(function(){
  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:[
      [3,3,"RANDOM"], [3,4,"FIRST"], [3,5,"LAST"],
      [4,3,"=RANDOM(1000)"], [4,4,"=FIRST(H3:H5)"], [4,5,"=LAST(H3:H5)"],
      [3,8,"1"],[4,8,"2"],[5,8,"3"]
    ]
  });
});