This is a migrated thread and some comments may be shown as answers.

[Solved] Multiple Detail levl tables in Hierarchy Grid

8 Answers 373 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Balamurali Venkatesan
Top achievements
Rank 1
Balamurali Venkatesan asked on 23 Oct 2008, 09:57 PM
Hi,

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

Sort by
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 24 Oct 2008, 01:51 PM
HI,

Any suggesstions on this would be greatly apprecited.

Thanks Bala
0
Joerg
Top achievements
Rank 1
answered on 24 Oct 2008, 02:03 PM
Hi,

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!
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 24 Oct 2008, 06:20 PM
HI ,

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
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 28 Jul 2009, 02:44 PM
HI,

Any updates on the above mentioned question would be of great help

Thanks
Bala
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 28 Jul 2009, 03:21 PM

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 =

"&nbsp;";

 

}

}

}

 

Thanks
Bala

0
Sebastian
Telerik team
answered on 31 Jul 2009, 10:57 AM
Hello Balamurali,

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.
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 04 Aug 2009, 08:02 AM
Hi,

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
0
Sebastian
Telerik team
answered on 04 Aug 2009, 08:20 AM
Hello 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.
Tags
Grid
Asked by
Balamurali Venkatesan
Top achievements
Rank 1
Answers by
Balamurali Venkatesan
Top achievements
Rank 1
Joerg
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or