How to rebind the RadGrid after close the RadWindow

JohnMalcom picture JohnMalcom · May 13, 2012 · Viewed 12.9k times · Source

I have a MasterPage with the RadAjaxManager.

I have a RadGrid in my ContentPage (Default.aspx). I would like to rebind the RadGrid after closing my RadWindow.

How can I rebind the RadGrid?

Answer

Brian Garson picture Brian Garson · May 13, 2012

On your content page (default.aspx) when you are calling your RadWindow to open, attach the property OnClientClose="refreshGrid". When the window is closed that function will be called.

<telerik:RadWindow runat="server" ID="myRadWin" OnClientClose="refreshGrid" />

And you can use a function like this to get your radGrid and rebind it clientside.

function refreshGrid() 
{        
      var masterTable = $find("<%=radGrid1.clientId%>").get_masterTableView();
      masterTable.rebind();
}

I've added this in for your case with the masterPages but leaving the above as it's also valid for anyone else stumbling upon this question as there are more than 1 way to accomplish this.

In your Rad Window page include a JavaScript function that you will use to close your RadWindow which will also make a callback to your parent page. The most elegant approach would be to make a generic call back function that is handled in your MasterPage which includes some arguments, and have that function delegate it to another more specific one for the page you're working on. A more generic approach is what I've described below:

In your RadWindow Page:

function CloseAndRefreshGrid() {
            var oWin = GetRadWindow();
            var parentWindow = oWin.BrowserWindow;
            $(oWin).ready(function()
            {
                oWin.close();
            });
            parentWindow.refreshGrid();            
        }

 function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including classic dialog
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)

            return oWindow;
        }

In your content page you can include this JavaScript:

 function refreshGrid() 
    {        
          var masterTable = $find("<%=radGrid1.clientId%>").get_masterTableView();
          masterTable.rebind();
    }