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

Get_MasterTableView() Is NULL

2 Answers 1118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 06 Dec 2013, 04:45 PM
All,

I have seen this issue reported by other people, but I have never had an issue. Now, it seems, I do. I've tried just about everything I know to resolve it, but while I find the gird on the page, the method get_masterTableView() always returns null.

My scenario involves my wanting to asynchronously load many grids on a page. Loading them normally has been pretty slow, so I am looking at faster ways to get the page up. As grid data populates, the grid shows up. Here is one of my Grid definitions:

<telerik:RadGrid ID="MyAnimalCategories" runat="server" AllowPaging="True" AllowSorting="True"
                   AutoGenerateColumns="False" AutoGenerateEditColumn="False" CellSpacing="0" GridLines="None"
                   OnNeedDataSource="MyAnimalCategoriesNeedDataSource" PageSize="20" OnSelectedIndexChanged="MyAnimalCategoriesSelectedIndexChanged">
                    <ClientSettings EnablePostBackOnRowClick="true">                                   
                       <Selecting AllowRowSelect="true" />
                       <ClientEvents OnRowSelected="SetDeviceText" OnCommand="function(){}" />
                   </ClientSettings>
                   <MasterTableView ShowHeadersWhenNoRecords="true" ClientDataKeyNames="AnimalCategoryId" DataKeyNames="AnimalCategoryId"  TableLayout="Fixed">
                       <Columns>
                           <telerik:GridBoundColumn DataField="AnimalCategoryName" HeaderText="Animal Species" UniqueName="Category">
                               <ItemStyle Wrap="false" />
                               <HeaderStyle Wrap="false" />
                           </telerik:GridBoundColumn>
                           <telerik:GridTemplateColumn ItemStyle-Width="50px" AllowFiltering="false" ReadOnly="true"
                               HeaderText="Status">
                               <ItemTemplate>
                                   <%# Convert.ToBoolean(Eval("IsActive").ToString())? "Active":"Inactive" %>
                               </ItemTemplate>
                           </telerik:GridTemplateColumn>
                       </Columns>
                   </MasterTableView>
               </telerik:RadGrid>

Here is the script
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
        <script type="text/javascript">
 
            function pageLoad(src, args) {
                var trainer = $('#<%= hdnTrainer.ClientID %>');
                var trainerId = trainer.val();
 
                PageMethod("LoadMySpecies", ["trainerId", trainerId], MySpecies, AjaxFailed);
                PageMethod("LoadMySubmissions", [], MySubmissions, AjaxFailed);
            }
 
            function PageMethod(fn, paramArray, successFn, errorFn) {
                var pagePath = window.location.pathname;
                //Create list of parameters in the form : {"paramName1":"paramValue1","paramName2":"paramValue2"}
                var paramList = '';
                if (paramArray.length > 0) {
                    for (var i = 0; i < paramArray.length; i += 2) {
                        if (paramList.length > 0)
                            paramList += ',';
                        paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
                    }
                }
                paramList = '{' + paramList + '}';
 
                //Call the page method
                $.ajax({
                    type: "POST",
                    url: pagePath + "/" + fn,
                    contentType: "application/json; charset=utf-8",
                    data: paramList,
                    dataType: "json",
                    success: successFn,
                    error: errorFn
                });
            }
 
            function MySubmissions(result) {
                var grid =  $find("<%= MySubmissions.ClientID %>");
                var masterTable = grid.get_masterTableView();
                var data = eval(result.d);
 
                masterTable.set_dataSource(data);
                masterTable.dataBind();
            }
 
            function MySpecies(result) {
                var grid = $find('<%= MyAnimalCategories.ClientID %>');
                var masterTable = grid.get_masterTableView();
                var data = eval(result.d);
                masterTable.set_dataSource(data);
                masterTable.dataBind();
            }
 
            function AjaxFailed(result) {
                alert(result.statusText);
            }
        </script>
</telerik:RadCodeBlock>


The script, as I said, finds the grid just fine, but the methods in the object do not include the get_masterTableView().

Thanks for any insight!

Sean~

2 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 11 Dec 2013, 09:41 AM
Hi Sean,

Thank you for contacting us.

A possible reason for the get_masterTableView() method to return null is if you are trying to access the MasterTableView before it is created. I noticed that you are trying to access the master table view on page load where the master table view might still not be created. I would recommend you to fire the PageMethod on GridCreated event handler. More information about GridCreated event is available in this help article:
OnGridCreated.

Regards,
Kostadin
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.
0
Robin
Top achievements
Rank 1
answered on 11 Dec 2014, 11:27 PM
I found this article useful in the case where I was creating a grid without giving it a datasource. Giving the grid a bogus datasource at first created the grid and raised the created event where I actually get the data.

http://www.telerik.com/forums/in-a-very-very-simple-client-side-binding-get-mastertableview-returns-null

Maybe it can be useful to someone else!
Robin
Tags
Grid
Asked by
Sean
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Robin
Top achievements
Rank 1
Share this question
or