Where are my nestedViews?

11 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 08 Nov 2010 Link to this post

    See the grid ...
    <telerik:RadGrid ID="RadGrid1" runat="server"
        AutoGenerateColumns="false"
        OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView HierarchyLoadMode="Client" ClientDataKeyNames="LastName, FirstName, Age">
            <Columns>
                <telerik:GridBoundColumn UniqueName="Col1" DataField="LastName" />
                <telerik:GridBoundColumn UniqueName="Col2" DataField="FirstName" />
            </Columns>
            <NestedViewTemplate>
                <telerik:RadTextBox ID="txtAge" runat="server" Label="Age:" Text='<%# Bind("Age") %>' />
                <telerik:RadTextBox ID="txtSex" runat="server" Label="Age:" Text='<%# Bind("Sex") %>' />
            </NestedViewTemplate>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowSelected="GridRowSelected" OnRowCreated="GridRowCreated" />
        </ClientSettings>
    </telerik:RadGrid>

    See the JavaScript ...

    function GridRowCreated(sender, e) {
        var x = e.get_gridDataItem();
        alert(x.get_nestedViews().length);
    }

    See my confused face when running the page and getting a zero back as result of nestedViews().length for each row.

    What I actually want to be able to do is get at the controls inside the nestedView for a given row on RowClick. But I've rather fallen at the first fence.

    -- 
    Stuart
  2. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 09 Nov 2010 Link to this post

    In the cold light of day I realise that the reason I can't see the nestedViews at this point is 'cos they prolly haven't been created yet.

    However, I can't see them when I handle the RowClicked event either.

    -- 
    Stuart
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tsvetina
    Admin
    Tsvetina avatar
    1875 posts

    Posted 10 Nov 2010 Link to this post

    Hi Stuart,

    You could try using the OnHierarchyExpanded client-side event of RadGrid in order to access the needed  objects, since it guarantees that the hierarchy has been expanded just before it was fired.

    Greetings,
    Tsvetina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 10 Nov 2010 Link to this post

    Hey there Tsvetina,

    Does this mean that I can't access the nestedView in the OnRowClick client event? Event if I have HierarchyLoadMode == Client?

    -- 
    Stuart
  6. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 10 Nov 2010 Link to this post

    And I assume I can get at the controls in the nestedView using something like this ...
    function HierarchyExpanding(sender, e) {
      var nestedView = e.get_gridDataItem().get_nestedViews();
      var o = $telerik.findControl(nestedView, "IDofControlToFind");
    }

    (I'm handling OnRowCreated, so I have access to get_gridDataItem())

    Yes?

    -- 
    Stuart
  7. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 10 Nov 2010 Link to this post

    Tried this ...
    function HierarchyExpanded(sender, e) {
      var nestedView = e.get_gridDataItem().get_nestedViews();
    }

    And nestedView is always null, even when, clearly, it isn't.

    -- 
    Stuart
  8. Tsvetina
    Admin
    Tsvetina avatar
    1875 posts

    Posted 12 Nov 2010 Link to this post

    Hi Stuart,

    The important part here is that get_nestedViews() returns a collection of client-side objects of type GridTableView (what the templated nested view is not). That is why this property returns null. A possible way to access the nested view created from template is to take its DOM element from the OnHierarchyExpanded event arguments:
    function GridHierarchyExpanded(sender, e) {
        var x = e.get_nestedViewItem();
    }


    Greetings,
    Tsvetina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 12 Nov 2010 Link to this post

    Tsvetina,

    Thanks for that. That gets me closer than I was.

    what the templated nested view is not
    You're got to understand the confusion though, yes? After all it's called a templated nested view, right?

    So, e.get_nestedViewItem returns the <TR> that contains the <TD> that contains the templated item.

    So, I thought that at that point I should be able to plug that in to a call to $telerik.findControl, but it seems not, or at least, it's  not that straightforward, is it?

    What I mean is, calling for example,
    var o = $telerik.findControl(x, "lblFirstName");

    is always going to return null, cos the rendered HTML sets the label's ID to something like "RadGrid1_ctl00_ctl06_lblFirstName".

    So, having found my nestedView that isn't a nestedView, how do I get a reference to an object inside the object? I can't use the usual technique of calling <% = lblFirstName.ClientID %>.

    I know that I'm not the brightest button in the box, but this seems difficult, even by my standards.

    -- 
    Stuart

  10. Tsvetina
    Admin
    Tsvetina avatar
    1875 posts

    Posted 16 Nov 2010 Link to this post

    Hi Stuart,

    You could try using $find  or $get (depending on the type of control you need to access) to get hold of the control in the nested view, where you should pass the DOM element returned by get_nestedViewItem() as a second argument.

    Kind regards,
    Tsvetina
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  11. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 20 Nov 2010 Link to this post

    Hi Tsvetina,

    I take your point about $get/$find, but I'm still left with the same issue wrt the ID of the item to get aren't I?

    -- 
    Stuart
  12. Tsvetina
    Admin
    Tsvetina avatar
    1875 posts

    Posted 24 Nov 2010 Link to this post

    Hello Stuart,

    Yes, since your hierarchy is loaded on the client, it gets more complicated to find the client ids (otherwise you could have stored them somewhere in the page on postback). In this scenario you can only search for the controls by tag name and id of the given tag, like it is done in the client edit with batch server update demo in the HideEditor() javascript method. For code sample on accessing some RadControls in the client edit scenario, you can also take a look at this forum thread.

    Regards,
    Tsvetina
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017