Since WebGrid.NET supports hierarchical mode, there are many scenarios related to the child table. For instance, how to get a child row's key value, expand the child table and many more. As a sample, we use key value to be obtained in ChildTable.
There are 2 ways to obtain key value at client side on the parent row, from server side and client side.
- Client-side
-
To obtain a key value on child table, we need a subtableId from the parent row that needs to be expanded first in order to render the sub table of the related key value.
SubtableId returns an array of a SubTable object which belongs to the table's current level that has been expanded before.
Here is the sample code on how to get the childRow keyValue of expanded parent row :
JavaScript Copy Code function getKeyValue()
{
var grid = ISGetObject("WebGrid1");
var selObj = grid.GetSelectedObject();
var row = selObj.GetRowObject();
if (row.Table.ChildTables.length > 0)
{
if (!row.ChildExpanded)
{
row.ExpandChildRow(true);
alert(grid.Tables["Orders"].SubTableIds[0].GetElement(WG40.BODY,
WG40.HTMLTABLE).childNodes[1].childNodes[0].keyValue);
}
}
}
With the latest client side API in WebGrid.NET Enterprise 5.0, there is another way to get the child row by using GetChildRows object based on defined relations.
JavaScript Copy Code function ExpChild()
{
var grid = ISGetObject("WebGrid1");
var selObj = grid.GetSelectedObject();
var row = selObj.GetRowObject();
if (row.Table.ChildTables.length > 0)
{
if (!row.ChildExpanded)
{
row.ExpandChildRow(true);
var childRows = row.GetChildRows("Orders");
var s = "";
for (var i=0; i<childRows.length; i++)
s += "\nOrderID: " + childRows[i].KeyValue;
debugger
alert("Customer '" + row.KeyValue + "' has " + childRows.length +
" orders.\nThe orders are:" + s);
}
}
}
These samples above show how to get the key value, obtain and set another property inside the object.
- Server-side
-
In ServerSide, we can simply use "WebGrid1.RetrieveClientLastSelectedObject().KeyValue" to get the child's or parent's key value. However, we need to click to the proper row before.
Overview
Getting Started
WebGrid Features Overview
Other Resources
Walkthrough Topics
How-to Topics