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

RadGrid Self-referencing Hierarchy - how to hide child items from parent level

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 2
Robin asked on 22 Jan 2014, 10:24 AM
Hello, 

I'm creating self-referencing hierarchy radgrid for menu permission and having some problem with populating data.
I want to display like below

Parent Item 1
- Child Item 1.1
- Child Item 1.2
Parent Item 2
- Child Item 2.1
- Child Item 2.2

After setting parentkeyname and keyname at SelfHierarchySetting, my child items display correctly under respective parent items.
But the problem is that those child items also display at parent level like below

Parent Item 1
- Child Item 1.1
- Child Item 1.2
Parent Item 2
- Child Item 2.1
- Child Item 2.2
Child Item 1.1
Child Item 1.2
Child Item 2.1
Child Item 2.2

How can I get rid of those additional child items instead of using TreeList control?

My data structure is as simple as shown in this help topic http://www.telerik.com/help/aspnet-ajax/grid-self-referencing-hierarchy.html.

I have prepared sample project and you can check below.
.aspx
<telerik:RadGrid ID="RadGrid1" runat="server"
        OnNeedDataSource="RadGrid1_NeedDataSource"
        AutoGenerateColumns="false">
        <MasterTableView AllowSorting="true" DataKeyNames="ID, ParentID" Width="100%">
            <SelfHierarchySettings ParentKeyName="ParentID" KeyName="ID" />
            <Columns>
                <telerik:GridBoundColumn UniqueName="colName" DataField="Name" HeaderText="Menu Name">
                    <ItemStyle Width="100px" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="colDesc" DataField="Description" HeaderText="Description">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowExpandCollapse="true">
        </ClientSettings>
    </telerik:RadGrid>

.cs
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GetDataTable();
        }
 
        private DataTable GetDataTable()
        {
            DataTable l_Table = new DataTable();
            l_Table.Columns.Add("ID");
            l_Table.Columns.Add("Name");
            l_Table.Columns.Add("Description");
            l_Table.Columns.Add("ParentID");
 
            l_Table.Rows.Add(new string[] { "1", "Menu 001", "Setup", null });
            l_Table.Rows.Add(new string[] { "2", "Menu 002", "Inventory", null });
            l_Table.Rows.Add(new string[] { "3", "Menu 003", "Reports", null });
 
            l_Table.Rows.Add(new string[] { "4", "Menu 004", "User", "1" });
            l_Table.Rows.Add(new string[] { "5", "Menu 005", "Item", "1" });
            l_Table.Rows.Add(new string[] { "6", "Menu 006", "Item type", "1" });
            l_Table.Rows.Add(new string[] { "7", "Menu 007", "UOM", "1" });
 
            l_Table.Rows.Add(new string[] { "8", "Menu 008", "Issuing", "2" });
            l_Table.Rows.Add(new string[] { "9", "Menu 009", "Receiving", "2" });
 
            l_Table.Rows.Add(new string[] { "10", "Menu 010", "Item details report", "3" });
            l_Table.Rows.Add(new string[] { "11", "Menu 011", "Inventory issuing details report","3" });
            l_Table.Rows.Add(new string[] { "12", "Menu 012", "Inventory receiving details report" });
 
            return l_Table;
        }


Thanks in advanced.
Robin

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jan 2014, 11:09 AM
Hello,

Please try with the below code snippet.

public void Page_Load(object sender, EventArgs e)
   {
       if (RadGrid1.EnableLinqExpressions)
       {
           RadGrid1.MasterTableView.FilterExpression = @"(Convert.ToInt32(iif(it[""ParentID""]==Convert.DBNull,null,it[""ParentID""])) = 0)";
       }
       else
       {
           RadGrid1.MasterTableView.FilterExpression = "ParentID=0";
       }
   }


Thanks,
Jayesh Goyani
0
Robin
Top achievements
Rank 2
answered on 22 Jan 2014, 11:26 AM
Got it! Thanks a lot.
I missed that part from demo :P
Tags
Grid
Asked by
Robin
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Robin
Top achievements
Rank 2
Share this question
or