Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
How to update a child row footer?
posted

I have an ultrawebgrid on my page with parent rows of employees and child rows of hours worked per month on different projects.

On the child rows I have a footer that sums all the hours worked during the months of the year (say Jan for example) for all projects. Using the following code I am able to loop thru the child rows for a column when one of the project hour columns have been updated and add up all the hours for projects for the updated column for the month.

Now I need to take the totalCellAmount and update the footer cell for the updated column. I have found a setFooterText and an example using it but I can't figure out how to make it work in my code for my child rows footer. 

Here is my code so far caculating the new footer amount but I can't figure out how to set the footer amount. Any help would be appreicated.

function  UpdateFooter( gridName, cellId )
{
    var column = igtbl_getColumnById(cellId);
   
var cell = igtbl_getCellById(cellId);
   
var row = cell.Row;
   
var parentRow = row.ParentRow;
   
var totalCellAmount = 0;

    for(var i=0; i<=row.ParentRow.VisChildRowsCount-1; i++)
    {
       
var cellAmount = parentRow.getChildRow(i).getCellFromKey(column.Key).getValue();
        totalCellAmount = parseFloat(totalCellAmount) + parseFloat(cellAmount);
        alert(
"Total %: " + totalCellAmount);
    }
}

  • 210
    Verified Answer
    posted

    Found that I didn't need to loop thru all rows so I have removed that loop code and now I am just looping thru the childrows where the update occurred.


    function UpdateFooter( gridName, cellId )
    {
        var grid = igtbl_getGridById(gridName); 
        var column = igtbl_getColumnById(cellId);
        var cell = igtbl_getCellById(cellId);
        var footercell = igtbl_getElementById(cellId);
        var row = cell.Row;
        var parentRow = row.ParentRow;
        var totalCellAmount = 0;
        var columnIndex = column.getRealIndex(row);
        var bandIndex = row.Band.Index;
        //make sure we have a child record 
     if(bandIndex=="1")
     {
         //loop thru the child rows and add up the totals
            for(var i=0; i<=row.ParentRow.VisChildRowsCount-1; i++)
            {
                //get amount from row
                var cellAmount = parentRow.getChildRow(i).getCellFromKey(column.Key).getValue();
                //add amount to cell total variable
                totalCellAmount = parseFloat(totalCellAmount) + parseFloat(cellAmount);
            }
            //get the footer row
            var footer=footercell.parentNode.parentNode.nextSibling.childNodes[0].childNodes[columnIndex];
            //update the footer text with the total amount
            footer.innerText=totalCellAmount;
        }
    }  

  • 210
    Verified Answer
    posted

    forgot the band index in my last answer.

    function UpdateFooter( gridName, cellId )
    {
        var grid = igtbl_getGridById(gridName); 
        var column = igtbl_getColumnById(cellId);
        var cell = igtbl_getCellById(cellId);
        var footercell = igtbl_getElementById(cellId);
        var row = cell.Row;
        var parentRow = row.ParentRow;
        var totalCellAmount = 0;
        var columnIndex = column.getRealIndex(row);
        var bCaculateComplete = 0;
        var bandIndex = row.Band.Index;
       
     if(bandIndex=="1")
     {
            for(var j=0;j<= grid.Rows.length-1;j++)
            {
                for(var i=0; i<=row.ParentRow.VisChildRowsCount-1; i++)
                {
                    bCaculateComplete = 1
                    var cellAmount = parentRow.getChildRow(i).getCellFromKey(column.Key).getValue();
                    totalCellAmount = parseFloat(totalCellAmount) + parseFloat(cellAmount);
                }
                if(bCaculateComplete==1)
                {
                    var footer=footercell.parentNode.parentNode.nextSibling.childNodes[0].childNodes[columnIndex];
                    footer.innerText=totalCellAmount;
                    break;
                }
            }
        }
    }  

     

  • 210
    Verified Answer
    posted

    Found the answer here is the code that works...

    function UpdateFooter( gridName, cellId )
    {
        var grid = igtbl_getGridById(gridName); 
        var column = igtbl_getColumnById(cellId);
        var cell = igtbl_getCellById(cellId);
        var footercell = igtbl_getElementById(cellId);
        var row = cell.Row;
        var parentRow = row.ParentRow;
        var totalCellAmount = 0;
        var columnIndex = column.getRealIndex(row);
        var bCaculateComplete = 0;
       
        for(var j=0;j<= grid.Rows.length-1;j++)
        {
            for(var i=0; i<=row.ParentRow.VisChildRowsCount-1; i++)
            {
                bCaculateComplete = 1
                var cellAmount = parentRow.getChildRow(i).getCellFromKey(column.Key).getValue();
                totalCellAmount = parseFloat(totalCellAmount) + parseFloat(cellAmount);
            }
            if(bCaculateComplete==1)
            {
                var footer=footercell.parentNode.parentNode.nextSibling.childNodes[0].childNodes[columnIndex];
                footer.innerText=totalCellAmount;
                break;
            }
        }
    }