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

Manual Load on Demand in Rad DataGrid

6 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 06 Aug 2010, 05:11 PM
Hi All,
I am exploring telerik datagrid for one of my requirement in project. I have tried the demo samples but none of them suits my requirement so please suggest me how I can achieve following requirement,
 
I need to show the hierarchy in grid dynamically. Initially I only know my base node (i.e. MasterTableView ) data. After loading the 

MasterTableView

 

data user will expand rows in MasterTableView & at the run time I will create DetailTables & bind grid with it. (so basically I want to create a child grid at runtime, the level of hierarchy is not defined it can grow to any level)

so the structure will be
WorkUnit
    Goals
        Objective
    WorkUnit
        Goals
            Employee
                Objective1
                Objective2  



Thansk in advance
KJ

 

6 Answers, 1 is accepted

Sort by
0
Kiran
Top achievements
Rank 1
answered on 07 Aug 2010, 07:14 AM
any updates on this? It is important for us to check if this kind of requirement is supported by Telerik?
0
Kiran
Top achievements
Rank 1
answered on 07 Aug 2010, 01:27 PM
do you need some more information? let me know if this kind on requirement is doable in Telerik?
0
Veli
Telerik team
answered on 12 Aug 2010, 09:03 AM
Hello Kiran,

This scenario can be implemented with a series of nested RadGrids. You will have to recursively create RadGrid instances in the NestedViewTemplate of the previous parent grid. To do that you need to:

1. Use RadGrid's ItemCreated event to add nested grids to each GridNestedViewItem that is created. This is the item that holds the nested template:

protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridNestedViewItem)
    {
        ((GridNestedViewItem)e.Item).NestedViewCell.Controls.Add(BuildInnerGrid());
    }
}

2. Use RadGrids' ItemCommand event to bind the inner grid:

protected void RadGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        RadGrid innerGrid = (RadGrid)dataItem.ChildItem.NestedViewCell.FindControl("InnerGrid");
        innerGrid.Rebind();
    }
}

3. Define the inner RadGrid instances recursively by attaching the same ItemCommand, ItemCreated and NeedDataSource event handlers to all of them:

protected RadGrid BuildInnerGrid()
{
    RadGrid innerGrid = new RadGrid();
    innerGrid.ID = "InnerGrid";
    innerGrid.NeedDataSource += new GridNeedDataSourceEventHandler(InnerGrid_NeedDataSource);
    innerGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
    innerGrid.ItemCommand += new GridCommandEventHandler(RadGrid_ItemCommand);
 
    innerGrid.MasterTableView.DataKeyNames = new string[] { "ID", "ParentID" };
    innerGrid.MasterTableView.NestedViewTemplate = new EmptyTemplate();
    innerGrid.MasterTableView.ShowHeader = false;
 
    return innerGrid;
}

What happens is that each inner grid that is rebound creates other inner grids in its nested items. The recursion is constrained by RadGrid's data - if a RadGrid's data source contains 0 items (indicating end of current hierarchical branch), no data items are created for the current RadGrid instance. This means no child grids will be instantiated further down.

Attaching a test page to demonstrate this approach.

All the best,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kiran
Top achievements
Rank 1
answered on 13 Aug 2010, 12:21 PM
Thanks!!! is there way I cen get tree like view? like adding .... lines
0
Kiran
Top achievements
Rank 1
answered on 19 Aug 2010, 07:08 AM
any updates on this?
0
Veli
Telerik team
answered on 19 Aug 2010, 02:02 PM
Hello Kiran,

Node lines like RadTreeView's are  not supported by RadGrid. If you need true TreeView experience, you can use RadTreeView and its NodeTemplate functionality to build content dynamically inside RadTreeView nodes.

Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Kiran
Top achievements
Rank 1
Answers by
Kiran
Top achievements
Rank 1
Veli
Telerik team
Share this question
or