get_masterTableView not always working

17 posts, 0 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 24 Apr 2009 Link to this post

    Hi,

    as described in this http://www.telerik.com/community/forums/aspnet-ajax/grid/client-api-onpopupshowing-eventargs-get-domevent-is-not-a-function.aspx#807122 post get_masterTableView() always returns null in some client functions.

    Even the trick OnCommand="function XX(){}" as posted in a different thread (and used in your samples) does not help.

    Are there some special client functions where get_masterTableView does / doesn't work?
    In the documentation http://www.telerik.com/help/aspnet-ajax/grid_get_mastertableview.html I can't find anything that this function only works in special cases.
    At least in OnPopUpShowing get_masterTableView always returns null.

    Regards

    Manfred
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Apr 2009 Link to this post

    Hi ManniAT,

    A possibe reasone for the get_masterTableView() method to return null is if you are trying to access the MasterTableView before it is created. If it is called after the GridCreated client-side event, it should always return the respective MasterTableView client object.

    However the OnPopUpShowing client-side event is fired before the OnGridCreated event. That is why the get_masterTableView() returns null.  

    You can try the attached sample for further reference.

    Regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 28 Apr 2009 Link to this post

    Hi Iana,

    is there a list or something like this which shows which events enable access to the mastertable and which not?

    Thank you for your reply - it helped a lot

    Regards

    Manfred
  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Apr 2009 Link to this post

    Hello ManniAT,

    I am afraid we have no such a list. However, here is a list of all RadGrid client-side events for a reference.

    What I would suggest you to do when you receive null after calling the get_masterTableView(), is to check if the event you need it fires before or after the OnGridCreated/OnMasterTableViewCreated events.

    Regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Valery
    Valery avatar
    45 posts
    Member since:
    Nov 2008

    Posted 15 Jan 2010 Link to this post

    I get a null reference also in another situation not mentioned here - if try using client-side data binding but assign the data binding properties in the code-behind OnPreRender instead of OnLoad. It seems assigning them on OnPreRender is too late and prevents client-side data binding from working at at all.
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 18 Jan 2010 Link to this post

    Hello Valery,

    Could you please send us the problematic page code? Thus I could check out the client-code used and confirm that you bound your grid properly.

    Greetings,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Valery
    Valery avatar
    45 posts
    Member since:
    Nov 2008

    Posted 18 Jan 2010 Link to this post

    Hi, Iana,

    Here is a code demonstrating two bugs:

    1. If the initial value of "LstEvent" is set to "OnPreRender", the rebinding function simply doesn't work (as mentioned - the get_masterTableView() function returns null). On the other hand, if the initial value is "OnLoad", everything works like charm. It works also if the value was "OnLoad" initially and then changed to "OnPreRender" (data binding settings seem to be stored from the previous request);
    2. I've decided to include another issue I have come across (but not related to the current topic) - this is the default sort expression. You could see that, although such an expression is set and arrow and coloring are correctly displayed, the "sortExpression" parameter to the web service method is not passed correctly. However clicking on the column header displays one more arrow which actually works.

    So here is the page markup:
    <asp:RadioButtonList ID="LstEvent" runat="server" AutoPostBack="true"
        <asp:ListItem Value="OnLoad" Text="OnLoad" /> 
        <asp:ListItem Value="OnPreRender" Text="OnPreRender" Selected="True" /> 
    </asp:RadioButtonList> 
    Last Update: <span id="lastUpdate"></span> 
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true"
        <MasterTableView> 
            <Columns> 
                <telerik:GridBoundColumn DataField="Time" HeaderText="Time" /> 
                <telerik:GridBoundColumn DataField="Number" HeaderText="Number" /> 
            </Columns> 
            <SortExpressions> 
                <telerik:GridSortExpression FieldName="Time" SortOrder="Descending" /> 
            </SortExpressions> 
        </MasterTableView> 
    </telerik:RadGrid> 
     
    <script type="text/javascript"
        function rebindGrid() { 
            var grid = $find('<%= RadGrid1.ClientID %>'); 
            var masterTableView = grid.get_masterTableView(); 
            masterTableView.rebind(); 
            var lastUpdateElement = $get('lastUpdate'); 
            lastUpdateElement.innerHTML = new Date().format('T'); 
            setTimeout(rebindGrid, 1000); 
        } 
        Sys.Application.add_load(rebindGrid); 
    </script> 
     

    Here is the code-behind:

    protected override void OnLoad(EventArgs e) 
        base.OnLoad(e); 
        if (LstEvent.SelectedValue == "OnLoad"
            InitializeDataBinding(); 
    protected override void OnPreRender(EventArgs e) 
        base.OnPreRender(e); 
        if (LstEvent.SelectedValue == "OnPreRender"
            InitializeDataBinding(); 
    private void InitializeDataBinding() 
        RadGrid1.ClientSettings.DataBinding.Location = "~/WebService1.asmx"
        RadGrid1.ClientSettings.DataBinding.SelectMethod = "GetData"

    And here is the web service code:

    private static DateTime _lastInsert = DateTime.Now; 
    private static readonly List<Item> Items = new List<Item>(); 
    private static readonly Random Random = new Random((int)DateTime.Now.Ticks); 
     
    [WebMethod] 
    [ScriptMethod] 
    public Dictionary<stringobject> GetData(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression) 
        if (DateTime.Now - _lastInsert > TimeSpan.FromSeconds(2)) 
        { 
            Items.Add(new Item { Time = DateTime.Now, Number = Random.NextDouble() }); 
            _lastInsert = DateTime.Now; 
        } 
        IEnumerable<Item> selection = Items; 
        if (sortExpression.Count > 0) 
            foreach (GridSortExpression expression in sortExpression) 
            { 
                switch (expression.FieldName) 
                { 
                    case "Time"
                        selection = (expression.SortOrder == GridSortOrder.Ascending ? selection.OrderBy(i => i.Time) : selection.OrderByDescending(i => i.Time)); 
                        break
                    case "Number"
                        selection = (expression.SortOrder == GridSortOrder.Ascending ? selection.OrderBy(i => i.Number) : selection.OrderByDescending(i => i.Number)); 
                        break
                    } 
                } 
        selection = selection.Skip(startRowIndex).Take(maximumRows); 
        return new Dictionary<stringobject
                { 
                    {"Data", selection.Select(i=> new { Time = i.Time.ToLongTimeString(), i.Number}).ToList()}, 
                    {"Count", Items.Count}, 
                }; 
     
    private class Item 
        public double Number; 
        public DateTime Time; 

    Best regards,
    Valery.
  9. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 21 Jan 2010 Link to this post

    Hi Valery,

    When adding the DataBinding settings for a RadGrid on PreRender, you need to explicitly rebind it in order the grid to be populated. Try modifying your code as below and let me know if it works:

    protected override void OnPreRender(EventArgs e)  
    {  
        base.OnPreRender(e);  
        if (LstEvent.SelectedValue == "OnPreRender")  
        {
            InitializeDataBinding();  
            RadGrid1.Rebind();
        }

    Regarding the second issue: I am afraid that declarative sort expressions are not supported for client-side bound RadGrid. If you want the problematic grid to be initially sorted, you can try modifying the GetData() method so it returns the desired results.

    Best wishes,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Valery
    Valery avatar
    45 posts
    Member since:
    Nov 2008

    Posted 21 Jan 2010 Link to this post

    Hi,

    I believe the OnPreRender thing should be mentioned in the documentation as well as all those tricky things regarding client data binding (you know - missing hierarchy and detail table view, declarative sort expressions, template columns and so on) as it takes some time to find out that such thing is actually not possible.

    Declarative sort expressions on web service bound data grids obviously doesn't work and it breaks the visualization of the header row as well. Is it possible to set table view's sort expressions via JavaScript for example and/or simulate clicking on the header of a column on_load?

    Thanks in advance,
    Valery.
  11. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 26 Jan 2010 Link to this post

    Hello Valery,

    Thank you for your feedback. We will do our best in order to document the client-side bound grid limitations in our online help.

    Regarding your last questions: To sort the grid manually on the client, you can try using its sort() method as described here.


    Regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Charan
    Charan avatar
    5 posts
    Member since:
    Aug 2012

    Posted 22 Jan 2013 Link to this post

    Hi,

    I have similar kind of problem.
    I have a grid inside update panel. i have a functionality to export the data to excel using ExportToExcel.
    After i have exported to excel, grid is refreshed by going to next page.
    Now if i try to open a popup which fetches value from radgrid. Am getting null when i use get_masterTableView().

    this works fine if i open popup without exporting to excel.

    Any solution for this issue?

    Thanks,
    Charan Kumar

  13. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 25 Jan 2013 Link to this post

    Hello Charan,

    Could you please elaborate a bit more on the issue you are facing? Have you excluded the export button from the ajax settings? If not please try the approach provided in the help topic below and let us know if it helps:
    http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html

    All the best,
    Maria Ilieva
    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.
  14. Charan
    Charan avatar
    5 posts
    Member since:
    Aug 2012

    Posted 31 Jan 2013 Link to this post

    Hi Maria,
    Here are few details hope it helps.

    ExportToExcel button is outside grid.
    I have registered button for full post back control using
    ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnExport);

    I have added alert for OnGridCreated event.
    Initially it gives alert on page index change but once export to excel is done it doesnt give any alert on page index change
    After export to excel, it seems grid is not getting created.

    onCommand event is also not getting fired.
    i am using telerik version 2008.2.1001.35.

    Thanks,
    Charan Kumar
  15. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 04 Feb 2013 Link to this post

    Hello Charan,

    As you are using rather old version of the controls there could be various issue that might be already fixed in the newer release. Therefor I would suggest you to upgrade your application to the latest official release and verify how it goes. If the issue still persists I would suggest you to open a regular support ticket and sand us sample runnable version of your application which demonstrates the problem. Thus we will be able to debug it locally and advise you further.

    Regards,
    Maria Ilieva
    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.
  16. Rajkumar
    Rajkumar avatar
    2 posts
    Member since:
    Nov 2008

    Posted 25 Jul 2013 Link to this post

    Hi ,

    I am new to Telerik controls. I have a requirement to collapse and expand the grand child lines to its immediate parent with a + symbol in one of the column. Can you please help with a sample code snippet to start with or the methods and properties I should use for achieving this behavior
  17. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jul 2013 Link to this post

    Hi Rajkumar,

    I guess you want to know about Hierarchy in RadGrid.Please have a look at the demo which describes about Hierarchy Grid - Declarative Relations or Hierarchy Grid - Programmatic Binding.
    In case, for your own icon for expand collapse,you can try the following code snippet.

    ASPX:
    <MasterTableView  ExpandCollapseColumn-ButtonType="ImageButton"  ExpandCollapseColumn-CollapseImageUrl="Images/Collapse.gif"  ExpandCollapseColumn-ExpandImageUrl="Images/Expand.gif" >


    Hope this helps,Let me know if any concern.

    Thanks,
    Shinu
  18. Rajkumar
    Rajkumar avatar
    2 posts
    Member since:
    Nov 2008

    Posted 25 Jul 2013 Link to this post

    Hi Shinu,

    Thanks for your reply.

    The requirement is to sum up the child lines and show as a single lie before expand and on expand it will show the details. Also grouping should apply from second level to its child. 

    On using the default option of grouping the user interface changes, currently we arer showing it as a table structure. Hence the user just needs another column with a + sign to expand and - to collapse.

    Cheers
    Raj
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017