Link to home
Start Free TrialLog in
Avatar of MandyProgza
MandyProgza

asked on

looping with javascript

Hi

I need help with creating a loop on an  Infragistics webgrid with javascript. The grid has 3 columns, I add values in column 1 and 2 and put the result in column 3, for each row.
Then I add values on the same column, row 1 and row 2 and put the result on row 0. I want it to be automatically done as values change on different rows/columns.

I used the attached and was only able to get part of the expected outcome.
I attached the code that I am currently using and the desired outcome on the excel spreadsheet.

Assistance will be greatly appreciated.

Regards
MandyProg
CellUpdateHandler.txt
example-of-grid.xlsx
Avatar of Badotz
Badotz
Flag of United States of America image

First off, this:
            if (Col10 == null) Col1 = 0;
            if (Col20 == null) Col2 = 0;

Open in new window

should be this:
            if (Col10 == null) Col10 = 0;
            if (Col20 == null) Col20 = 0;

Open in new window

Second, you need to use the same variable names.

This:
var total = 0;

Open in new window

should be this:
var Total = 0;

Open in new window


Further, I'd change the code as follows:
 function Grid1AfterCellUpdateHandler(gridName, cellId) {

            var activeRow = igtbl_getActiveRow(gridName);

            // Calculate Total for current year
            // Get values from the grid and populate the variables    	    	
            var Col1 = activeRow.getCell(9).getValue() || 0;
            var Col2 = activeRow.getCell(10).getValue() || 0;

            activeRow.getCell(11).setValue(parseFloat(Col1) + parseFloat(Col2));

            // Calculate total for previous year
            var Col10 = activeRow.getCell(13).getValue() || 0;
            var Col20 = activeRow.getCell(14).getValue() || 0;

            activeRow.getCell(15).setValue(parseFloat(Col10) + parseFloat(Col20));
        }

Open in new window

Avatar of MandyProgza
MandyProgza

ASKER

Hi

Thanks for the recommendations. The column on the last row only gets the correct total if I tab into the column, else it displays the old figure. Anyway to have it updated? if the cell on the column gets updated regardless of which column/cell has the focus?

e.g. I change row2 on column 1, then row 0 of column 1 gets the new column total, third column on row 2 also gets updated but the grand total for the last column on row 0 doesn't get updated.

MandyProg.
ASKER CERTIFIED SOLUTION
Avatar of Badotz
Badotz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot!
No worries - glad to help.