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

get_masterTableView not working

5 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Jesse asked on 14 Jul 2014, 11:46 PM
I've had a tough time trying to figure out how to access my grid on client side. I've tried everything I could find, and nothing seems to work. I FINALLY got my grid object ($find didn't work for me), but now get_masterTableView() isn't doing anything. If I step through the javascript, it steps into the line and just disappears into some WebResource.axd abyss and never returns. I don't get any javascript errors.

If I try to run the function in the console, it says "undefined is not a function".

Here's my code

<script type="text/javascript">
    function GridCreated(grid) {
        var mtv = grid.get_masterTableView();
        var pageIndex = mtv.get_currentPageIndex();
        alert(pageIndex);
    }
</script>
<radG:RadGrid ID="rgResults" runat="server" AllowMultiRowSelection="True" AllowPaging="True"
            AllowSorting="True" EnableAJAX="False" GridLines="None" OnItemCommand="rgResults_ItemCommand" OnItemDataBound="rgResults_ItemDataBound"
            PageSize="20"
            Skin="Default" Width="100%" OnPageIndexChanged="rgResults_PageIndexChanged" OnSortCommand="rgResults_SortCommand" OnInit="rgResults_Init" OnPreRender="rgResults_PreRender">
            <ClientSettings ApplyStylesOnClient="True">
                <ClientEvents OnGridCreated="GridCreated(this);" />
            </ClientSettings>
            <ItemStyle CssClass="griditemtext" />
            <HeaderStyle CssClass="gridheadertext" />
            <FooterStyle CssClass="gridfootertext" />
            <AlternatingItemStyle CssClass="gridalternetitemtext" />
            <PagerStyle CssClass="gridpagertext" Mode="NumericPages" />
            <CommandItemStyle CssClass="gridcommandtext" />
            <SelectedItemStyle CssClass="gridselecteditemtext" />
            <MasterTableView AutoGenerateColumns="False"
                DataKeyNames="Article Number" Font-Bold="False" Font-Italic="False" CommandItemDisplay="None" Font-Overline="False"
                Font-Strikeout="False" Font-Underline="False" GridLines="Both">
                <ExpandCollapseColumn Visible="False">
                    <HeaderStyle Width="19px" />
                </ExpandCollapseColumn>
                <RowIndicatorColumn Visible="False">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <PagerStyle Mode="NumericPages" />
                <Columns/>
            </MasterTableView>
        </radG:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Jesse
Top achievements
Rank 1
answered on 15 Jul 2014, 12:02 AM
As a note, I did get this funky syntax to work:

var mtv = <%= rgResults.ClientID %>.MasterTableView;

Is there a better way, and is there a reason why this is working, but the functions to retrieve the values are not working?
0
Accepted
Pavlina
Telerik team
answered on 15 Jul 2014, 08:47 AM
Hello Jesse,

I took the provided code and prepared a sample runnable project based on it. You can find it attached to this message. Give it a try and modify your code accordingly.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jesse
Top achievements
Rank 1
answered on 15 Jul 2014, 05:14 PM
Thank you Pavlina. I was able to run the code you supplied. Unfortunately, when I applied my master page, it stopped working. Do you know why that might be? I'm getting a nullreferenceexception. Here's the aspx page after I made my changes:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="Navigation.master" CodeFile="SearchResultsUnVoided.aspx.cs" Inherits="Grid" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <telerik:RadCodeBlock ID="CodeBlock1" runat="server">
        <script type="text/javascript">
            function GridCreated(sender, args) {
                var grid = $find("<%= rgResults.ClientID %>");
                var mtv = grid.get_masterTableView();
                var pageIndex = mtv.get_currentPageIndex();
                alert(pageIndex);
            }
        </script>
    </telerik:RadCodeBlock>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptCombine="true">
        </telerik:RadScriptManager>
        <telerik:RadGrid ID="rgResults" runat="server" AllowMultiRowSelection="True" AllowPaging="True"
            AllowSorting="True" EnableAJAX="False" GridLines="None" OnNeedDataSource="rgResults_NeedDataSource"
            PageSize="20"
            Skin="Default" Width="100%">
            <ClientSettings>
                <ClientEvents OnGridCreated="GridCreated" />
            </ClientSettings>
            <ItemStyle CssClass="griditemtext" />
            <HeaderStyle CssClass="gridheadertext" />
            <FooterStyle CssClass="gridfootertext" />
            <AlternatingItemStyle CssClass="gridalternetitemtext" />
            <PagerStyle CssClass="gridpagertext" Mode="NumericPages" />
            <CommandItemStyle CssClass="gridcommandtext" />
            <SelectedItemStyle CssClass="gridselecteditemtext" />
            <MasterTableView AutoGenerateColumns="true"
                DataKeyNames="ID" Font-Bold="False" Font-Italic="False" CommandItemDisplay="None" Font-Overline="False"
                Font-Strikeout="False" Font-Underline="False" GridLines="Both">
                <ExpandCollapseColumn Visible="False">
                    <HeaderStyle Width="19px" />
                </ExpandCollapseColumn>
                <RowIndicatorColumn Visible="False">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <PagerStyle Mode="NumericPages" />
            </MasterTableView>
        </telerik:RadGrid>
    </form>
</asp:Content>
0
Jesse
Top achievements
Rank 1
answered on 15 Jul 2014, 06:19 PM
Ah! I think I may have figured it out. There's a difference between:

Telerik.WebControls.GridBoundColumn
and 
Telerik.Web.UI.GridBoundColumn

Maybe different versions of RadGrid? Whatever it is, I'm using the latter now, and it seems to be working so far. The only issue now is that it looks like this version has changed the way you apply a skin. I was previously using this:

<ClientSettings ApplyStylesOnClient="True">

It seems as though ApplyStylesOnClient is no longer supported. Is there a different way I should be applying the styles now?

Thanks!
0
Accepted
Konstantin Dikov
Telerik team
answered on 18 Jul 2014, 01:03 PM
Hi Jesse,

I am really glad to see that the initial issue have been resolved.

As for your new question, the ApplyStylesOnClient property have been removed and is no longer needed. Detailed information on this you could find at the following help article:
As for the RadGrid appearance and style, please take a look at the following help articles:
Hope this helps.

 

Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Jesse
Top achievements
Rank 1
Answers by
Jesse
Top achievements
Rank 1
Pavlina
Telerik team
Konstantin Dikov
Telerik team
Share this question
or