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

Select a row when the Expand Collapse is clicked

2 Answers 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sharmin
Top achievements
Rank 1
Sharmin asked on 01 Oct 2013, 08:31 PM
Hi,

I have a hierarchical  grid, which shows the list of Orders Closed for the Year > Month > Order Number fashion.
That is the first level grid will have the list of years which the orders are created in descending order. For e.g., 2013, 2012, 2011 etc
The second level grid will show the Months for the Orders created. For e.g., January, February, March etc..
The third level grid will show the Order Numbers. For e.g, 1000, 1001, 1002 etc. 
My grid ASPX code is as below:
<Telerik:RadGrid ID="rgYears" runat="server" AutoGenerateColumns="False" CellSpacing="0"
     Width="200px" GridLines="None" Skin="Office2007" Font-Names="Calibri,Arial" AllowSorting="true">
     <MasterTableView DataKeyNames="DateClosedYear" ShowHeader="false">
         <Columns>
             <Telerik:GridBoundColumn DataField="DateClosedYear" HeaderText="Year" UniqueName="DateClosedYear">
             </Telerik:GridBoundColumn>
         </Columns>
         <SortExpressions>
             <Telerik:GridSortExpression FieldName="DateClosedYear" SortOrder="Descending" />
         </SortExpressions>
         <DetailTables>
             <Telerik:GridTableView runat="server" Name="MonthDetails" DataKeyNames="DateClosedMonth"
                 Width="176px" NoDetailRecordsText="No Child Records" ShowHeader="false">
                 <Columns>
                     <Telerik:GridBoundColumn DataField="DateClosedMonthName" HeaderText="Month" UniqueName="DateClosedMonth">
                     </Telerik:GridBoundColumn>
                 </Columns>
                 <ParentTableRelation>
                     <Telerik:GridRelationFields DetailKeyField="DateClosedYear" MasterKeyField="DateClosedYear" />
                 </ParentTableRelation>
                 <DetailTables>
                     <Telerik:GridTableView runat="server" Name="OrderDetails" DataKeyNames="OrderNumber"
                         Width="143px" NoDetailRecordsText="No Child Records" ShowHeader="true">
                         <Columns>                                           
                             <Telerik:GridButtonColumn ButtonType="LinkButton" CommandName="SelectOrderNumber"
                                 DataTextField="OrderNumber" FilterControlAltText="FilterOrderNumber column" HeaderText="Order Number"  UniqueName="OrderNumber" SortExpression="OrderNumber" ShowSortIcon="false">
                             </Telerik:GridButtonColumn>
                         </Columns>
                         <ParentTableRelation>
                             <Telerik:GridRelationFields DetailKeyField="DateClosedMonth" MasterKeyField="DateClosedMonth" />
                         </ParentTableRelation>
                     </Telerik:GridTableView>
                 </DetailTables>
             </Telerik:GridTableView>
         </DetailTables>
     </MasterTableView>
 </Telerik:RadGrid>


I store the Order number when ever the user cilcks on it to see the details. But when the user comes back, I want to show him the last Order number he accessed which I could do with the below code.
'rgYears dataGrid is already databound
'Get all the Months and Years for Orders Closed
'The below section of the code is called at Page Load
Dim OrdersMonthYear = dHelper.OrdersClosedMonthYear(oNumber) 'Get the Month and Year of the last accessed Order
If (rgYears.MasterTableView.Items.Count > 0) Then
    Dim rgYearsItem As GridDataItem = rgYears.MasterTableView.FindItemByKeyValue("DateClosedYear", OrdersMonthYear.DateClosedYear)
    If Not IsNothing(rgYearsItem) Then
        rgYearsItem.Expanded = True
        Dim rgMonthsItem As GridDataItem = rgYearsItem.ChildItem.NestedTableViews(0).FindItemByKeyValue("DateClosedMonth", OrdersMonthYear.DateClosedMonth)
        If Not IsNothing(rgMonthsItem) Then
            rgMonthsItem.Expanded = True
            Dim rgOrdersItem As GridDataItem = rgMonthsItem.ChildItem.NestedTableViews(0).FindItemByKeyValue("OrderNumber", oNumber) 'Last Accessed Order Number from the table
            If (Not IsNothing(rgOrdersItem)) Then
                rgOrdersItem.Selected = True
            End If
        End If
    End If
End If

I am facing problems with the Expand Collapse. I need to Collapse all the expanded grids when the user clicks on Expand. If the last accessed Order Number is of the expanded Year > Month, I want that row to be selected.

For e.g., Order 1003 was closed on 2013 > July. So when I click August, July should be Collapsed and August Month should be shown. Also when I expand July, August should be closed,  July must be expanded and select the Order number 1003.

2 Answers, 1 is accepted

Sort by
0
Sharmin
Top achievements
Rank 1
answered on 03 Oct 2013, 02:38 PM
No replies yet?
0
Angel Petrov
Telerik team
answered on 04 Oct 2013, 02:16 PM
Hi Sharmin,

As far as I understand the requirement you want to enable a single expand for the second level of the grid. By following the approach in this help article you should be able to meet the requirements. One other thing, from the code I noticed that you have already obtained a reference to the child table on the second level(using the NestedTableViews collection). That said you already have the child table and you can traverse it's items and collapse them according to the criteria.

One thing which I noticed. From the comments it seems that the code logic is executed in the PageLoad event. Try executing it on a later stage of the page life cycle so that the grid items can be populated(use PreRender for example).

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Sharmin
Top achievements
Rank 1
Answers by
Sharmin
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or