Grid math calculations

calaultions on gris cells may result erros, how can I manage or catch errors.

(like to avoid N.an display when dividing by 0)?


You can get cell’s value with method mygrid.cellById(rowId,cellIndex).getValue() and then check if this value valid or not. You should make this validation after grid was fully loaded. To detect if grid was filly loaded you can use “onXLE” evet (availible at PRO vestion only) or 2nd parameter on loadXML method:


mygrid.loadXML(“grid.xml”,function(){


//make validation


})

Also, custom methods can be used in formulas. Instead of
=c1/c2
You can use
=my_operation(c1,c2)
and define in JS code
function my_operation(c1,c2){
if (c2) return c1/c2;
return “error”;
}

Ok, Thanks,

but
is it possible to make this on the init statement : (  mygrid.setColTypes(“tree,ron,ron,ron,price,ron[=
my_operation(c1,c2)],ron[=c3/c2100],price[=c4/c11000],price[=c4/c2*100],price[=c4/c3]”);
since I want to avoid this from the server.
it looks like a parsing error or something else preventing using this method.

Thanks,
Zafrir Ron
(license 256976565)

The tricky point is the commas inside the custom methods - they are the same as string separators, so string parsed incorrectly
You can use

mygrid.setDelimiter("|");
mygrid.setColTypes(“tree|ron|ron|ron|price|ron[=my_operation(c1,c2)]|ron[=c3/c2100]|price[=c4/c11000]|price[=c4/c2*100]|price[=c4/c3]”)
mygrid.setDelimiter(",");

Great,
Thanks,
it did solve my problem!!