I’m struggeling with some code.
I have 3 columns
Fisrt column is “amount to pay”
Second column is amount “already paid”
Thirth column is “percentage paid”
The percentace paid is taken out the XML file so there are no calculations in the grid.attachHeader.
In the footer I used #stat_total to calculate the first two colums. So now that I have a total of “Amount to pay” and total of “Already paid” I want the percentage op those 2.
What I do here is manual calculate the sum of the column, then do the percentage calculation of 2 columns, then format the result with decimal point and add a “%” sing to it. Then return it back to the footer label.
the reason why I manual calculate the sum is that I didn’t found a way to get the footer label to a vaiable. The footerlabel is set by #stat_total. If the footerlabel is set manualy then it’s possible to get that label and set it in a var for later use.
I hope I can be of some help to someone.
If you have some tips about this code to improve it, plz let me know as I’m still in a learning phase.
greetz
function procentInFooter(){
var col13 = sumColumn(13);
var col14 = sumColumn(14);
var col15 = ToProcent(col14,col13);
myGrid.setFooterLabel(3,col15);
var col16 = sumColumn(16);
var col14b = sumColumn(14);
var col17 = ToProcent(col16,col14b);
myGrid.setFooterLabel(5,col17);
var col16b = sumColumn(16);
var col18 = sumColumn(18);
var col19 = ToProcent(col18,col16b);
myGrid.setFooterLabel(7,col19);
var col20 = sumColumn(20);
var col21 = sumColumn(21);
var col22 = ToProcent(col21,col20);
myGrid.setFooterLabel(10,col22);
}
function sumColumn(columnIndex){
var teller=myGrid.getRowsNum();
var som = 0;
for(var i=0; i<teller; i++){
var findCell = myGrid.cellByIndex(i,columnIndex);
var getVal = findCell.getValue();
som = som + parseFloat(getVal);
}
return som;
}
function ToProcent(col1,col2){
var floatNumber = 0;
var floatNumberFixed = 0;
if(col2==0){
floatNumberFixed = "Error. div by zero";
return floatNumberFixed
}
else{
floatNumber =((parseFloat(col1)/parseFloat(col2)) * 100).toFixed(2);
floatNumberFixed = floatNumber.replace('.',',') + "%";
return floatNumberFixed;
}
}
Ah oke that was the problem I use number formatting.
Well it time to make some work on learning how to make some custom functions to replace the parseFloat.
Anyway thx alot for your time and info.
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan