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

How do you recommend refreshing the Grid client-side?

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nathan J Pledger
Top achievements
Rank 2
Nathan J Pledger asked on 03 Feb 2009, 03:58 PM
Hi,

I have a grid:

<telerik:RadGrid ID="radGridUsers" runat="server" 
                         AllowAutomaticDeletes="false"  
                         AllowAutomaticInserts="false" 
                         AllowAutomaticUpdates="false" 
                         AllowCustomPaging="false" 
                         AllowMultiRowSelection="true" 
                         AllowPaging="true" 
                         AllowSorting="true" 
                         AutoGenerateColumns="false" 
                         AutoGenerateDeleteColumn="false" 
                         AutoGenerateEditColumn="false" 
                         GroupingEnabled="false" 
                         PageSize="20" 
                         ShowFooter="false" 
                         ShowGroupPanel="false" 
                         ShowHeader="true" 
                         ShowStatusBar="false" 
                         Skin="Vista" 
                         style="width:auto"                          
                         > 
                        <ClientSettings AllowColumnHide="false" AllowColumnsReorder="false" AllowDragToGroup="false" AllowExpandCollapse="false" AllowRowHide="false" AllowRowsDragDrop="false" EnablePostBackOnRowClick="false" EnableRowHoverStyle="true" ReorderColumnsOnClient="true"
                            <ClientEvents /> 
                            <ClientMessages /> 
                            <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> 
                            <Resizing AllowColumnResize="true" AllowRowResize="false" ClipCellContentOnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="false" /> 
                            <Scrolling AllowScroll="false" /> 
                        </ClientSettings>     
                        <MasterTableView ClientDataKeyNames="Username"
                            <Columns> 
                                <telerik:GridClientSelectColumn CommandName="Select" DataType="System.Boolean"
                                    <HeaderStyle Width="20" /> 
                                    <ItemStyle Width="20" /> 
                                </telerik:GridClientSelectColumn> 
                                <telerik:GridTemplateColumn HeaderText="Status" UniqueName="userIcon"
                                 
                                </telerik:GridTemplateColumn> 
                                <telerik:GridBoundColumn DataField="Username" AllowSorting="true" AllowFiltering="false" 
                                    DataType="System.String" Display="true" HeaderText="Username" ReadOnly="true" Resizable="true" ShowSortIcon="true" UniqueName="Username"></telerik:GridBoundColumn> 
                                <telerik:GridTemplateColumn UniqueName="windowsAccount" HeaderText="Windows Account"
                                 
                                </telerik:GridTemplateColumn> 
                                <telerik:GridBoundColumn DataField="FirstName" AllowSorting="true" AllowFiltering="false" 
                                    DataType="System.String" Display="true" HeaderText="First Name" ReadOnly="true" Resizable="true" ShowSortIcon="true" UniqueName="Username"></telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="LastName" AllowSorting="true" AllowFiltering="false" 
                                    DataType="System.String" Display="true" HeaderText="Last Name" ReadOnly="true" Resizable="true" ShowSortIcon="true" UniqueName="Username"></telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Position" AllowSorting="true" AllowFiltering="false" 
                                    DataType="System.String" Display="true" HeaderText="Position" ReadOnly="true" Resizable="true" ShowSortIcon="true" UniqueName="Username"></telerik:GridBoundColumn> 
                                 
                            </Columns> 
                        </MasterTableView> 
                          
                          
                     
                         
                    </telerik:RadGrid> 

The user can display Windows which can be used to modify the settings of the items. When the RadWindows close, I have some JavaScript firing. I would like this JavaScript to refresh the grid to reflect the change, preferably in an AJAXy way.

How would you recommend doing this? I could put it in an RadAjaxPanel, but wouldn't that be expensive, bandwidth-wise?




2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2009, 07:19 AM
Hi Nathan,

Give a try with the following client side code on closing the RadWindow to refresh the Grid.

ASPX:
 

 
<telerik:RadWindow ID="RadWindow1" runat="server" Behavior="Close"  OnClientClose="OnClientClose"  VisibleOnPageLoad="true" ></telerik:RadWindow>

 

JS:
<script type="text/javascript"
  
function OnClientClose() 
var oWin=GetRadWindow(); 
 
  if (oWin) 
    { 
       oWin.BrowserWindow.refreshGrid() 
        oWin.Close(); 
    } 
 
 
function GetRadWindow() 
    var oWindow = null
   if (window.radWindow) 
    { 
      oWindow = window.radWindow; 
      alert(oWindow) 
    } 
  else if (window.frameElement.radWindow) 
   { 
    oWindow = window.frameElement.radWindow; 
   } 
  return oWindow; 
 
 }  
 
 
 function refreshGrid() 
     { 
       $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");   
     } 
</script> 


CS:
 protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
    { 
        if (e.Argument == "Rebind"
        { 
 
            RadGrid1.Rebind(); 
        } 
    } 


You can also refer the following demo link where the Grid is being refreshed on the client side.
Window Editing

Thanks
Shinu



0
Nathan J Pledger
Top achievements
Rank 2
answered on 05 Feb 2009, 10:39 AM
Thanks for that.
That works ... for one window!
My other window is not $finding the RadAjaxManager.

Both Windows call the following callback:

    <script type="text/javascript" language="javascript"
 
        function migOnWindowClosedHandler(sender, eventArgs) { 
            var ajaxMgr=$find("ctl00_ctl00_radAjaxManager"); 
            if (ajaxMgr) { 
                ajaxMgr.ajaxRequest("RebindUsersGrid"); 
            } 
            else { 
                window.location = window.location; 
            } 
        } 
         
    </script> 
 
 

Both Windows are opened using the following function (with different URLs):

function migOpenDialog(url, width, height) { 
    var oManager=GetRadWindowManager(); 
    var oWnd=oManager.open(url) 
    oWnd.setSize(width,height); 
    oWnd.center(); 
    oWnd.set_modal(true) 
    oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move+Telerik.Web.UI.WindowBehaviors.Close); 

Neither Window interacts with the RadWindowManager or the host page.
I seem to be having a few problems with $find not finding controls that are there, and this behavour seems the strangest of all. Am I misusing it?
Tags
Grid
Asked by
Nathan J Pledger
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Nathan J Pledger
Top achievements
Rank 2
Share this question
or