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

get_masterTableView not always working

16 Answers 633 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 24 Apr 2009, 06:58 PM
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

16 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Apr 2009, 07:15 AM
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.
0
ManniAT
Top achievements
Rank 2
answered on 28 Apr 2009, 11:19 AM
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
0
Iana Tsolova
Telerik team
answered on 28 Apr 2009, 11:55 AM
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.
0
Valery
Top achievements
Rank 2
answered on 15 Jan 2010, 10:00 AM
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.
0
Iana Tsolova
Telerik team
answered on 18 Jan 2010, 01:26 PM
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.
0
Valery
Top achievements
Rank 2
answered on 18 Jan 2010, 02:59 PM
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.
0
Iana Tsolova
Telerik team
answered on 21 Jan 2010, 01:24 PM
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.
0
Valery
Top achievements
Rank 2
answered on 21 Jan 2010, 01:48 PM
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.
0
Iana Tsolova
Telerik team
answered on 26 Jan 2010, 03:38 PM
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.
0
Charan
Top achievements
Rank 1
answered on 22 Jan 2013, 12:29 PM
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

0
Maria Ilieva
Telerik team
answered on 25 Jan 2013, 02:31 PM
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.
0
Charan
Top achievements
Rank 1
answered on 31 Jan 2013, 10:41 AM
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
0
Maria Ilieva
Telerik team
answered on 04 Feb 2013, 12:14 PM
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.
0
Rajkumar
Top achievements
Rank 1
answered on 25 Jul 2013, 07:24 AM
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
0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2013, 08:17 AM
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
0
Rajkumar
Top achievements
Rank 1
answered on 25 Jul 2013, 11:59 AM
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
Tags
Grid
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
ManniAT
Top achievements
Rank 2
Valery
Top achievements
Rank 2
Charan
Top achievements
Rank 1
Maria Ilieva
Telerik team
Rajkumar
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or