Problems working with ExpandColumns

2 posts, 0 answers
  1. David
    David avatar
    19 posts
    Member since:
    Nov 2008

    Posted 01 Feb 2010 Link to this post

    I am attempting to use a hierarchical grid and am having a number of issues with the ExpandColumn.  I want to hid the auto-generated expand column placed in the first column of all levels and add a formatted image for the expand column in the last column.  I have managed the last requirement by placing a GridButtonColumn with a Command handler to expand/collaspe the parent grid item.  This works, sort of.

    The bigger problem comes when expanding the second level table.  I used the examples provided for others for hiding the expandcolumn in the first column and that seems to work until I expand the grid.  Then the expandcolumn for the first level is shown - moving the second level over by 250px. (which is the size of the first grids first data column).  I can see that the code to hide the expandcolumns is the last thing running - as expected as it is called from the grid's PreRender event.

    It may help to show some code:

    Here is the grid:

        <telerik:RadGrid ID="statusGrid" runat="server" EnableViewState="false" AllowPaging="false" AllowSorting="false" 
                         OnNeedDataSource="statusGrid_NeedDataSource" OnItemCreated="statusGrid_ItemCreated"   
                         OnDetailTableDataBind="statusGrid_DetailTableDataBind" OnPreRender="statusGrid_PreRender" 
                         AutoGenerateColumns="false" AllowMultiRowSelection="false" Width="98%" OnItemCommand="statusGrid_ItemCommand">  
            <MasterTableView EnableViewState="false" EnableNoRecordsTemplate="true" GridLines="None" 
                             AllowFilteringByColumn="false" ShowHeader="false" ShowFooter="false" 
                             DataKeyNames="StatusID" HorizontalAlign="Right" Width="100%" Name="Status" 
                             HierarchyLoadMode="ServerOnDemand" HierarchyDefaultExpanded="false" > 
                <NoRecordsTemplate> 
                    No Patients or Forms available.  
                </NoRecordsTemplate> 
                <ItemStyle BackColor="#CDE3DD" /> 
                <Columns> 
                    <telerik:GridTemplateColumn> 
                        <ItemStyle HorizontalAlign="Left" Width="250px" CssClass="statusInfo" /> 
                        <ItemTemplate>                          
                            <asp:Label ID="status" runat="server" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn> 
                        <ItemStyle Width="350px" BorderStyle="None" /> 
                        <ItemTemplate> 
                            &nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn> 
                        <ItemStyle HorizontalAlign="Right" Width="250px" CssClass="statusItem" /> 
                        <ItemTemplate> 
                            <asp:Label ID="patientCount" runat="server" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridButtonColumn UniqueName="levelOne" ButtonType="ImageButton" CommandName="Expand" ImageUrl="../images/header_menu.gif" > 
                        <ItemStyle HorizontalAlign="Right" CssClass="statusButton" /> 
                    </telerik:GridButtonColumn> 
                </Columns>                          
                <DetailTables> 
                    <telerik:GridTableView DataKeyNames="PatientID" EnableViewState="false" AllowSorting="false" 
                                           AllowPaging="true" PageSize="5" OnDataBound="patientGrid_DataBound" Name="Patients" > 
                        <ParentTableRelation> 
                            <telerik:GridRelationFields DetailKeyField="StatusID" MasterKeyField="StatusID" />                          
                        </ParentTableRelation> 
                        <Columns> 
                            <telerik:GridTemplateColumn> 
                                <ItemStyle HorizontalAlign="Left"  Width="250px"/>  
                                <ItemTemplate>                          
                                    <asp:Label ID="patient" runat="server" /> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <ItemStyle HorizontalAlign="Right" Width="250px"/>  
                                <ItemTemplate> 
                                    <asp:Label ID="formCount" runat="server" /> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridExpandColumn UniqueName="levelTwo" CollapseImageUrl="../images/expand.jpg" ExpandImageUrl="../images/expand.jpg" > 
                                <HeaderStyle HorizontalAlign="Right" Width="10px" />                              
                            </telerik:GridExpandColumn> 
                        </Columns> 
                        <DetailTables> 
                            <telerik:GridTableView DataKeyNames="FormID" EnableViewState="false"   
                                                   AllowPaging="true" PageSize="20" OnDataBound="formGrid_DataBound" Name="Forms" > 
                                <ParentTableRelation> 
                                    <telerik:GridRelationFields DetailKeyField="PatientID" MasterKeyField="PatientID" /> 
                                </ParentTableRelation> 
                                <HeaderStyle CssClass="listItem" /> 
                                <ItemStyle CssClass="listItem" /> 
                                <Columns> 
                                    <telerik:GridButtonColumn HeaderText="Form Name" DataTextField="SurveyName" SortExpression="SurveyName" ButtonType="LinkButton">  
                                        <ItemStyle ForeColor="#1A3F62" Font-Bold="false" Font-Underline="false" /> 
                                    </telerik:GridButtonColumn> 
                                    <telerik:GridBoundColumn DataField="PatientInitials" HeaderText="Patient Initials" SortExpression="PatientInitials" ReadOnly="true" /> 
                                    <telerik:GridBoundColumn DataField="Comment" HeaderText="Comment" SortExpression="Comment" ReadOnly="true" /> 
                                    <telerik:GridBoundColumn DataField="VisitName" HeaderText="Visit Name" SortExpression="VisitName" ReadOnly="true" /> 
                                    <telerik:GridDateTimeColumn DataField="LastChange" HeaderText="Last Change" SortExpression="LastChange" ReadOnly="true" /> 
                                    <telerik:GridBoundColumn DataField="ChangedBy" HeaderText="Changed By" SortExpression="ChangedBy" ReadOnly="true" /> 
                                </Columns> 
                            </telerik:GridTableView> 
                        </DetailTables> 
                    </telerik:GridTableView> 
                </DetailTables> 
            </MasterTableView> 
        </telerik:RadGrid> 
     

    Here is the code run from the statusGrid-PreRender:

        /// <summary>  
        /// Hides the expand column recursively.  
        /// </summary>  
        /// <param name="view">The view.</param>  
        private void HideExpandColumnRecursive( GridTableView view )  
        {  
            GridItem[] nestedViewItems = view.GetItems( GridItemType.NestedView );  
            foreach ( GridNestedViewItem nestedViewItem in nestedViewItems )  
            {  
                foreach ( GridTableView nestedView in nestedViewItem.NestedTableViews )  
                {  
                    if ( nestedView.Items.Count == 0 )  
                    {  
                        nestedViewItem.Visible = false;  
     
                        TableCell cell = nestedView.ParentItem["ExpandColumn"];  
                        cell.Visible = false;  
                          
                        cell.Controls[0].Visible = false;  
                    }  
     
                    if ( nestedView.HasDetailTables )  
                    {  
                        HideExpandColumnRecursive( nestedView );  
                    }  
                }  
            }  
        }  
     

    and attached is a screen shot of the expanded grid:    

    Any help is greatly appreciated.

    David
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Feb 2010 Link to this post

    Hello David,

    I reviewed your setup, and the code looks correct. However, in order to further track the problem,
    it will be best if you open a formal support ticket, and send us a small working project, demonstrating the setup, and the unwanted behavior. We will debug it locally, and get back to you with additional information.

    Best wishes,
    Pavlina
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top