Iam trying to build a Hierachy Grid with multiple levels in it.
The DetailsTable levels will not be fixed.
Assume like the first row might have 2 levels
Second row might have 3 levels .
For that we just created the mastertableview declaratively and created the child levels by getting the MAX levels for a given product.. Assume like we have a product table where the maximum level is 5 we created 5 level detail table dynamically.
We use the NeedDatasource and the DetailTableBind.
The only problem we have is wehn we go throught he levels by expanding the last level which doesn't have data is aslo having the PLUS sign to be expanded..Only when we expand that we come to know like it has no data..
Is there a way like we can dynamically read the the number of levels of detail tables and remove it .
Assume we have a query that would give us the number of kevels for each mastertable data product..so when i click on the product to expand i would connect to databse and get the no of levels for that product and based on that i need to remove the extra detial tables which we created.
Assume we created 5 levels initially .I click to expnad a product and at that time i identify the level by connecting to database and assume its 3.
Now I should be able to remove those additonal 2 levels so that the last level doesn't have a plus sign..
Thanks
Bala
8 Answers, 1 is accepted
Any suggesstions on this would be greatly apprecited.
Thanks Bala
try the following:
| Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView) |
| Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView) |
| For Each nestedViewItem As GridNestedViewItem In nestedViewItems |
| For Each nestedView As GridTableView In nestedViewItem.NestedTableViews |
| If nestedView.Items.Count = 0 Then |
| Dim cell As TableCell = nestedView.ParentItem("ExpandColumn") |
| cell.Controls(0).Visible = False |
| nestedViewItem.Visible = False |
| End If |
| If nestedView.HasDetailTables Then |
| HideExpandColumnRecursive(nestedView) |
| End If |
| Next |
| Next |
| End Sub |
And in the PreRender-Event:
HideExpandColumnRecursive(Grid1.MasterTableView)
Hope this helps!
Thanks for your information.
We are actually setting the datasource for child tables only on detailtablebind.
So even if we use your code to loop throught he nestedtableviews its not going to know the levels..
bcoz the items count would always be zero for the next child as its set only the detailtablebind.
Thanks
Bala
Any updates on the above mentioned question would be of great help
Thanks
Bala
We are programatically creating a Hierarchy Grid with multiple levels on it.
Inorder to hide the Plus image for the items that don't have sub levels we are actually hiding the plus image in the item databound event by checking a "Count" variable that would be populated on the need datasource and detail table bind events.
Everything works fine except for an issue
Assume there are two items,
one with a plus image as it has 3 child items
another item without plus iomaghe as it doesn't have any child item
When I click the plus image of the first item its displays the 3 items below it without the plus sign on it which is the expected behaviour.
But at the the same time its adding a plus image on the second item ,which was not displaying the plus sign on page load.This ideally should not happen as it doen't have any child items.
Below is the code snippet how we bind the grid.Unfortunately we wouldn't be able to provide a working sample
protected void RadGridProducts_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
int dbId = (int)HttpContext.Current.Session["INSTR_ID"];
List<InstrProduct> products = _presenter.PopulateProductsData(dbId, 0, 30);
RadGrid grid = (RadGrid)source;
grid.DataSource = products;
}
}
protected
void RadGridProducts_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
GridDataItem parentItem = e.DetailTableView.ParentItem;
int productId = Convert.ToInt32(parentItem.GetDataKeyValue("Id"));
string[] datakeyNames = { "Id","ParentId","ProductLevel","Tag" };
e.DetailTableView.DataKeyNames = datakeyNames;
GridRelationFields relationFields = new GridRelationFields
{
MasterKeyField =
"Id",
DetailKeyField =
"ParentId"
};
String htmlColor = "#6699CC";
//Color backColor = ColorTranslator.FromHtml(htmlColor);
//e.DetailTableView.HeaderStyle.BackColor = backColor;
e.DetailTableView.ParentTableRelation.Add(relationFields);
e.DetailTableView.Width =
Unit.Percentage(100);
e.DetailTableView.DataSource = _presenter.GetChildProducts(productId);
}
protected void RadGridProducts_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem && !(e.Item is GridDataInsertItem))
{
int productCnt = Convert.ToInt32(((InstrProduct)e.Item.DataItem).ProductChildCount);
if (productCnt == 0)
{
e.Item.Cells[0].Controls[0].Visible =
false;
//Added to help empty cell render correctly
e.Item.Cells[0].Text =
" ";
}
}
}
Thanks
Bala
I think that the implementation from the following topic in the RadGrid for ASP.NET AJAX online documentation will help you remove the expand/collapse images from items which do not have child records in the grid hierarchy. Feel free to alter/extend the solution for your custom scenario.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks for the update,But the solution which you suggested might not solve our issue.
Our detail table would bind only after clicking the expand/Collapse image as we have set the HierarchyLoad Mode as ServerOnBind.
As per your solution on page load the mastertable view would not have any detail table associted with it until i click the expand collpase image,so in this case it would hide the expand collapse column eventhough that particlkuar row has child records
Also since you are traversing through the nestedtable views it would be very slow as we have multiple levels.
Is there any other approach for this.Any suggestion would be of great help.
Thanks and Regards
V.Balamurali
Unfortunately this is the solution which should work as expected in various scenarios. The idea is to choose ServerBind or Client load more for the hierarchy (or combine them and set them on different levels) and choose HierarchyDefaultExpanded = true at each level of the hierarchy.
Thus the items will be available and you can determine whether a particular record has child records or not in order to hide its expand/collapse image.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.