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

Where is a practical example of finding a control in a nested view?

3 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 27 Feb 2013, 07:00 PM
I'm looking at http://www.telerik.com/help/aspnet-ajax/grid-griddataitem-get-nestedviews.html and http://www.telerik.com/help/aspnet-ajax/grid-traversing-detail-tables-items-in-grid.html.

I have a RadGrid with a header and detail records.  What I need is to be able to find a control in the popup FormTemplate of a detail in JavaScript.  Given what little I've been able to find so far I would expect it to be something like this:

   var grid = $find('<%= RadGrid1.ClientID %>');
   var masterTable = grid.get_masterTableView();                                               
   var dataItems = masterTable.get_dataItems();                                                                                            
   var editForm = dataItems[0].get_nestedViews()[0];
   var comboAssigned = $telerik.findControl(editForm, "ddlAssignedTo");       

--------------------------------------

My apologies for once again posting too quickly.  After some trial and (much) error I believe I've found an answer.  
(Is this reasonably optimal?  I know I'm going to have to use get_editFormItem if the template is in Edit mode.)

      var grid = $find('<%=RadGrid1.ClientID %>');
      var masterTable = grid.get_masterTableView();
      var dataItems = masterTable.get_dataItems();
      var nestedView = dataItems[0].get_nestedViews()[0];
      var editForm = nestedView.get_insertItem();
      var comboAssigned = $telerik.findControl(editForm, 'ddlAssignedTo');


3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Mar 2013, 11:59 AM
Hello Boris,

Your solution should work correctly and basically, it seems to be the optimal one, having in mind that we are not familiar with your specific scenario.

One little issue you can face is that when you are trying to update an item instead of inserting a new one, you will need to use nestedView.get_editItems()[index] instead of get_insertItem() to access the edit form. I suppose you are perfectly aware of that.

Hope this helps.

Regards,
Eyup
the Telerik team
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 their blog feed now.
0
Boris
Top achievements
Rank 1
answered on 04 Mar 2013, 01:13 PM
Actually what I did finally was modify traverseChildTables to get the nestedView object.

   function  traverseChildTables (gridTableView) {
          var dataItems = gridTableView.get_dataItems();
          for (var i = 0; i < dataItems.length; i++) {
             if (dataItems[i].get_nestedViews().length > 0) {
                var nestedView = dataItems[i].get_nestedViews()[0];
                if (nestedView.get_name() == 'Details')
                      return nestedView;
                else
                      getChildTable(nestedView);
             }
          }
  }

Then I did my usual test to get the edit form.
 if (AddMode) 
         editForm = nestedView.get_insertItem();                                                    
 else
        editForm = nestedView.get_editItems()[0].get_editFormItem();

(I am not a JavaScript expert.  This whole thing seems a little non-intuitive.)
0
Eyup
Telerik team
answered on 07 Mar 2013, 12:22 PM
Hello Boris,

You can also check out the following topic:
http://www.telerik.com/help/aspnet-ajax/grid-traversing-detail-tables-items-in-grid.html

And the server-side approach:
http://www.telerik.com/help/aspnet-ajax/grid-hide-expand-collapse-images-when-no-records.html

I hope this will prove helpful.

Kind regards,
Eyup
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Boris
Top achievements
Rank 1
Share this question
or