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

Hiding expand/collapse images when no records with NeedDataSource

5 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Suzy
Top achievements
Rank 2
Suzy asked on 07 Nov 2014, 10:11 AM
I have a telerik datagrid and I would like to hide the collapse button when there are no childs available. It does not work as I would aspect.
This is my code :

<telerik:RadGrid ID="grdTest" runat="server" AutoGenerateColumns="false" PageSize="20" AllowSorting="true" AllowPaging="true" ShowGroupPanel="true" ShowFooter="true"
 MasterTableView-HierarchyDefaultExpanded="true"
 OnNeedDataSource="grdTest_NeedDataSource" OnItemCreated="grdTest_ItemCreated" OnPreRender="grdTest_PreRender" >
 
 <MasterTableView AllowSorting="true" DataKeyNames="TicketID, TopTicketID" Width="100%" HierarchyLoadMode="ServerBind">
 <SelfHierarchySettings ParentKeyName="TopTicketID" KeyName="TicketID" />
 <Columns>
 <telerik:GridBoundColumn SortExpression="TicketID" HeaderText="Ticket" HeaderButtonType="TextButton" DataField="TicketID" UniqueName="TicketID"></telerik:GridBoundColumn>
  </Columns>
 </MasterTableView>
 <ClientSettings AllowExpandCollapse="true"></ClientSettings>
 </telerik:RadGrid>

my C# code behind :

protected void grdTest_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
         {
            grdTest.DataSource = BLogic.ITTickets.GetStructure(null, null, 0);
         }
 
  protected void grdTest_PreRender(object sender, EventArgs e)
        {
            HideExpandColumnRecursive(grdTest.MasterTableView);
        }
        public void HideExpandColumnRecursive(GridTableView tableView)
        {
            GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
            foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
            {
                foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
                {
                    if (nestedView.Items.Count == 0)
                    {
                        TableCell cell = nestedView.ParentItem["ExpandColumn"];
                        cell.Controls[0].Visible = false;
                        cell.Text = " ";
                        nestedViewItem.Visible = false;
                    }
                    if (nestedView.HasDetailTables)
                    {
                        HideExpandColumnRecursive(nestedView);
                    }
                }
            }
        }

The BLogic.ITTickets.GetStructure(null, null, 0);  calls a stored procedure on sql server that gives me back the list with the data.

Can anyone please tell me what I do wrong?

Kind regards

Suzy

5 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 11 Nov 2014, 11:37 AM
Hi Suzy,

In order to hide the expand/collapse images when there are no records in self-referencing hierarchy you should follow the approach demonstrated in the following help article instead: *The self-referencing hierarchy is no longer recommended and the above article is not available anymore

Please follow all the instructions from the help article and see if everything will work as expected on your end too.


Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Suzy
Top achievements
Rank 2
answered on 12 Nov 2014, 08:03 AM
I tried this and it works almost correct. 
All the bellow levels are shown open.  When I close for example the first one, everything is ok, but when I close another when, the >-sign of the the first one is gone....

​
0
Suzy
Top achievements
Rank 2
answered on 13 Nov 2014, 07:34 AM
Hi Konstantin,

I already followed the steps in the help article you mentioned before I posted this on the forum.  Did not fix my problem.

I fixed it by setting the HierarchyLoadMode to ServerBind not ServerOnDemand

Kind regards

Suzy
0
Sam
Top achievements
Rank 1
answered on 08 Jun 2016, 11:37 PM
Link is dead!!! Frustrating!!
0
Konstantin Dikov
Telerik team
answered on 13 Jun 2016, 10:33 AM
Hello Sam,

The linked help article is no longer available, because self-referencing data structure we have RadTreeList controls:
As for removing the expand/collapse icons you could refer to the following help article instead:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Suzy
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Suzy
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Share this question
or