Hiding expand/collapse images when no records with NeedDataSource

6 posts, 0 answers
  1. Suzy
    Suzy avatar
    66 posts
    Member since:
    Nov 2014

    Posted 07 Nov 2014 Link to this post

    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

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 11 Nov 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Suzy
    Suzy avatar
    66 posts
    Member since:
    Nov 2014

    Posted 12 Nov 2014 in reply to Konstantin Dikov Link to this post

    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....

  5. Suzy
    Suzy avatar
    66 posts
    Member since:
    Nov 2014

    Posted 13 Nov 2014 in reply to Konstantin Dikov Link to this post

    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
  6. Sam
    Sam avatar
    1 posts
    Member since:
    Nov 2014

    Posted 08 Jun in reply to Konstantin Dikov Link to this post

    Link is dead!!! Frustrating!!
  7. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 13 Jun Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017