Author Topic: Using Formulas in multiple Columns  (Read 1593 times)

joaosales

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 20
    • View Profile
Using Formulas in multiple Columns
« on: March 19, 2018, 03:44:22 pm »
Hi,

is there a way to set a set the same formula as dataIndx for multiple columns, but have the formula use a condition depending on the column?
example:
Code: [Select]
["RandomFormula", function(ui){

                    var total = 0;

                    for (var k in ui) {

                        if (!isNaN(ui[k])) {
                            if (k.indexOf("-") > 0) total += ui[k];
                        }
                    }
                   if(column X) total = total/10;
                   if(column Y) total = total*10;
}]

I'm trying to build the table dynamically , so i would need extra information about the column, other than the dataIndx, to know how to calculate.

Thanks,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Using Formulas in multiple Columns
« Reply #1 on: March 19, 2018, 09:43:14 pm »
Same function can be used for multiple formulas by using a named function instead of anonymous function.

Code: [Select]
[[dataIndx1, fn], [dataIndx2, fn2],...]

2nd parameter to the function is column which can help you get column specific information inside the function.

Code: [Select]
function fn(rowData, column){
 ..
}