User Profile & Activity

Robert Brooks Member

Ok, I did some poking and found what appears to be the solution. Making these changes allows the calling functions to remain unchanged.

Old (getElementsByTagName):

function GetHeaderCells(gridID) {
    var grid = ISGetObject(gridID);
    if (grid == null) { return null; }
    // Get parent or child WebGridRow object
    //var theTable = grid.RootTable;
    var theTable = grid.GetSelectedObject().ToRowObject().SubTable;
    return theTable.GetElement(WG40.COLHEADER, WG40.HTMLDIV).getElementsByTagName("td");
}
function GetFooterCells(gridID) {
    var grid = ISGetObject(gridID);
    if (grid == null) { return null; }
    // Get parent or child WebGridRow object
    //var theTable = grid.RootTable;
    var theTable = grid.GetSelectedObject().ToRowObject().SubTable;
    return theTable.GetElement(WG40.COLFOOTER, WG40.HTMLDIV).getElementsByTagName("tr")[1].getElementsByTagName("td");
}

New (children):

function GetHeaderCells(gridID) {
    var grid = ISGetObject(gridID);
    if (grid == null) { return null; }
    // Get parent or child WebGridRow object
    //var theTable = grid.RootTable;
    var theTable = grid.GetSelectedObject().ToRowObject().SubTable;
    return theTable.GetElement(WG40.COLHEADER, WG40.HTMLCELL).children[0].children[0].children;
}
function GetFooterCells(gridID) {
    var grid = ISGetObject(gridID);
    if (grid == null) { return null; }
    // Get parent or child WebGridRow object
    //var theTable = grid.RootTable;
    var theTable = grid.GetSelectedObject().ToRowObject().SubTable;
    return theTable.GetElement(WG40.COLFOOTER, WG40.HTMLCELL).children[1].children[1].children;
}

Of course, I'm worried about the possiblity that I got the right answer from the wrong place, so if you could confirm that what I'm going to use is stable, I'd appreciate it.

That gets me the footer element, if I know it's element 6.

How do I implement the more generic solution, where we use GetColumnIndexByName/GetHeaderCells to get the element number? It returns 8, which sends me to the wrong child.

I tried getting the header info using something similar, but the direct equivalent (using WG40.COLHEADER instead of WG40.COLFOOTER) doesn't work. In fact, there isn't even a children[1].

?theTable.GetElement(WG40.COLHEADER, WG40.HTMLCELL).children
{Count = 1}
    [Raw View]: {object}
    [0]: {object}

There's also the question: if we shouldn't be using "getElementsByTagName", then why is that the only method mentioned in this thread until now? Should we be using "children" (and WG40.HTMLCELL instead of WG40.HTMLTABLE) in the original solution as well? If so, we need new equivalents for these:

// Get grid's rows
var rows = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLTABLE).getElementsByTagName("tr");
// Get header cells
return grid.RootTable.GetElement(WG40.COLHEADER, WG40.HTMLDIV).getElementsByTagName("td");
// Get footer cells
return grid.RootTable.GetElement(WG40.COLFOOTER, WG40.HTMLDIV).getElementsByTagName("tr")[1].getElementsByTagName("td");

 



Sorry about that. You can remove the .js references and add this at the beginning of the <script> section:

        function OnAfterInitialize(a, b, c, d) {
            var grid = ISGetObject(a);
            if (grid.RootTable.GetRowsCount() == 0) grid.ResetStatus(true);
        }

 Thanks!

I'm attaching samples that I hope will help. I think I've removed everything that won't compile outside our environment.

I put alert boxes at two spots in the code. One shows that we did successfully scroll through the child rows and compute a total... the other shows that the function that was supposed to return the footer row, didn't do so.

Thanks a ton for your assistance! It's *so* close now!

Note: Y'all might want to test the "Attach File" function with Chrome (20.0.1132.34 beta-m). I had some trouble. :)

(Sorry for the delayed reply... I didn't realize I needed to turn on reply notification)

The suggestion for using SubTable helped a lot! I can iterate through the rows. But I can't seem to find the cell where I need to update the total.

In the snippet below, I'm able to iterate through the rows by substituting the SubTable object for the RootTable object:

var grid = ISGetObject(gridID);
// Get parent or child WebGridRow object
//var theTable = grid.RootTable; // parent
var theTable = grid.GetSelectedObject().ToRowObject().SubTable; // child
var rows = theTable.GetElement(WG40.BODY, WG40.HTMLTABLE).getElementsByTagName("tr");
// iterate through all rows
for (var i = 0; i < rows.length; i++) {
   if (rows[i].type == "Record") {
      sCellValue = grid.GetRowByElement(rows[i]).GetCell(columName).Value;

With a similar substitution, I'm able to correctly grab the index to the header column. The GetHeaderCells function returns an array of 20 columns, and my "Percent" column is [7]:

headerCells = theTable.GetElement(WG40.COLHEADER, WG40.HTMLDIV).getElementsByTagName("td");

But something's wrong with the code that's supposed to get all the footer cells. There are only 2 elements returned by this call, and neither is my "Percent" column:

footerCells = theTable.GetElement(WG40.COLFOOTER, WG40.HTMLDIV).getElementsByTagName("tr")[1].getElementsByTagName("td");

I suspect I need to be looking somewhere other than row index [1]... but where?

This approach seems to work quite well for your average grid, and the techinique is used throughout my team's application.


However, I'm unable to adapt it for use with a *child grid*, and the error I'm getting implies that there's something strange going on inside the GetElement method.


This code works just fine:

?grid.RootTable.GetElement(WG40.BODY, WG40.HTMLTABLE).getElementsByTagName("tr")
{Count = 40}
    [Raw View]: {object}
    [0]: {object}
// etc

But when I try to reference a child table, I get a very strange error:

?grid.RootTable.ChildTables[0].GetElement(WG40.BODY, WG40.HTMLTABLE).getElementsByTagName("tr")
'tagName' is null or not an object

 The error seems to be coming from the GetElement method, because it's the same when I don't call the .getElementsByTagName method:

?grid.RootTable.ChildTables[0].GetElement(WG40.BODY, WG40.HTMLTABLE)
'tagName' is null or not an object

Both grid.RootTable and grid.RootTable.ChildTables[0] return a valid-looking WebGridTable object, so I  would figure I'm on the right track. Is there a different way I should be accessing the Child table, perhaps?

All times are GMT -5. The time now is 12:48 AM.
Previous Next