Issues with NestedViewSettings

5 posts, 0 answers
  1. marksweat
    marksweat avatar
    28 posts
    Member since:
    Apr 2007

    Posted 07 Jul 2017 Link to this post

    I've got a Master Grid, with a NestedViewTemplate that has a sub grid in it. I want this sub grid to databind when a row in the Master Grid is expanded. The sub grid's binding method needs the data key from the Master Grid row to bind. I'm having trouble connecting this key to the sub grid, its always 0. I've reviewed the documention for NestedViewTemplates and NestedViewSettings but must still be doing something wrong. The docs for the NestViewTemplates refer to the working demo but it uses a Label to stash the Master Table row key rather than the NestedViewSettings which I'm trying to use. I've have been able to bind the sub grid table using various techniques such as stashing the Master Table row key in the label or using NeedsDataSource. These other methods won't work for me as they want to bind sub grid data for all rows of the master grid when the page is loaded and this is too slow.

     

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
         <telerik:RadScriptManager ID="BudgetAdjustmentScriptManager" runat="server" EnablePartialRendering="true"></telerik:RadScriptManager>

             <telerik:RadGrid ID="BudgetAdjustmentRadGrid" runat="server" Width="100%" AllowPaging="True" AllowSorting="true" AutoGenerateColumns="False" PageSize="20" DataSourceID="BugetAdjustmentRadGrid_ObjectDataSource" 
                AlternatingItemStyle-BackColor="#e6e6e6" ShowFooter="True">
                <MasterTableView CommandItemDisplay="Top" Width="100%" DataKeyNames="budget_adjustment_master_id" ShowGroupFooter="true" Name="Master">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="FontIconButton" UniqueName="Edit"></telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="name" HeaderText="Name" UniqueName="name" MaxLength="50" ></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="number" HeaderText="Number" UniqueName="number" readonly="true"></telerik:GridBoundColumn>
                    </Columns>
                    <NestedViewSettings DataSourceID="BudgetAdjustmentItem_ObjectDataSource">
                          <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="budget_adjustment_master_id" MasterKeyField="budget_adjustment_master_id"  />
                          </ParentTableRelation>
                    </NestedViewSettings>
                    <NestedViewTemplate>
                        <asp:Panel ID="InnerContainer" runat="server" CssClass="viewWrap" Visible="True">
                            <telerik:RadGrid ID="BudgetAdjustmentItemRadGrid" runat="server" DataSourceID="BudgetAdjustmentDetail_ObjectDataSource" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" >
                                    <MasterTableView DataKeyNames="budget_adjustment_master_id, budget_adjustment_detail_id" HierarchyLoadMode="ServerOnDemand" PageSize="10" CommandItemDisplay="Top">
                                    <Columns>
                                        <telerik:GridEditCommandColumn ButtonType="FontIconButton" UniqueName="Edit"></telerik:GridEditCommandColumn>
                                        <telerik:GridBoundColumn DataField="budget_adjustment_detail_id" HeaderText="ID" SortExpression="budget_adjustment_detail_id" UniqueName="budget_adjustment_detail_id" ReadOnly="true"></telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="budget_adjustment_operation" HeaderText="Operation" SortExpression="budget_adjustment_operation" UniqueName="budget_adjustment_operation" ReadOnly="true"></telerik:GridBoundColumn> 
                                        </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>

                        </asp:Panel>
                    </NestedViewTemplate>
                </MasterTableView>
            </telerik:RadGrid>
                            <asp:ObjectDataSource ID="BudgetAdjustmentDetail_ObjectDataSource" runat="server" TypeName="BudgetAdjustmentDetailDAL" SelectMethod="Get" SortParameterName="sort_expression" >
                                <SelectParameters>
                                    <asp:Parameter Name="budget_adjustment_master_id" Type="Int32" />
                                    <asp:Parameter Name="project_node_master_id" DefaultValue="25" Type="Int32" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="BudgetAdjustmentItem_ObjectDataSource" runat="server" TypeName="BudgetAdjustmentMasterDAL" SelectMethod="Get">
            <SelectParameters>
                <asp:Parameter Name="budget_adjustment_master_id" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="BugetAdjustmentRadGrid_ObjectDataSource" runat="server" TypeName="BudgetAdjustmentMasterDAL" SelectMethod="Get" SortParameterName="sort_expression">
            <SelectParameters>
                <asp:Parameter Name="project_node_master_id" DefaultValue="33" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </asp:Content>

  2. Eyup
    Admin
    Eyup avatar
    4014 posts

    Posted 12 Jul 2017 Link to this post

    Hello Mark,

    The secret here is to set the Visible property of the InnerContainer Panel to false initially. This will prevent the rendering and binding of every inner grid. You can switch it to true only for the expanded rows:
    http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/hierarchy-with-templates/defaultcs.aspx

    That should do the trick. I am also sending a sample RadGrid web site to demonstrate a programmatic way of binding for NestedViewTemplate.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. marksweat
    marksweat avatar
    28 posts
    Member since:
    Apr 2007

    Posted 12 Jul 2017 in reply to Eyup Link to this post

    So you don't recommend the method I'm using for binding with the NestedViewSettings?
  4. marksweat
    marksweat avatar
    28 posts
    Member since:
    Apr 2007

    Posted 12 Jul 2017 in reply to Eyup Link to this post

    I guess I have a lot of questions here.

    1. Any idea why the NestedViewSetting setup I'm using in the above example isn't work?

    2. How do you recommend communicating the data key of the Master Table row that is opened to the NestedTableView grid? Is NestedViewSetting not designed to do this? Why does the Telerik example mentioned above use a Label to communicate the data key?

    3. Can you illuminate how the HierarchyLoadMode="ServerOnDemand" function work for the Sub Grid? For example, why is the setting ignored or doesn't work if the InnerContainer Panel is initially visible?

     

    --Mark

  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 18 Jul 2017 Link to this post

    Hello Mark,

    Detailed information on this matter could be found in the following help article:
    Hope this helps.


    Regards,
    Konstantin Dikov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top