Rebinf two grids in JavaScript

6 posts, 0 answers
  1. Krzysztof
    Krzysztof avatar
    29 posts
    Member since:
    Aug 2008

    Posted 25 Nov 2008 Link to this post

    Hi

    I have two simple grids on web page.
    When I try to call function like :

    function Rebind()
    {  
        tableView = $find("Grid1").get_masterTableView();
        tableView.rebind();
    }

    Grid1 going to rebind and show new dataSet.

    But if I call :

    function Rebind()
    {  
        tableView = $find("Grid1").get_masterTableView();
        tableView.rebind();
        tableViewW = $find("Grid2").get_masterTableView();
        tableViewW.rebind();
    }

    ... Grid1 and Grid2 do not show new dataSet. Shows information about update on it's status bar only. Why ??

    Regards
    Krzysztof
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Nov 2008 Link to this post

    Hello Krzysztof,

    Generally rebind() method will request the server (post-back or ajax request if the the grid is ajaxified). The second rebind may not be able to reach the server. Such approach will be successful only if the grid data-binding is asynchronous - for example client-side data-binding.

    Greetings,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Krzysztof
    Krzysztof avatar
    29 posts
    Member since:
    Aug 2008

    Posted 25 Nov 2008 Link to this post

    OK.
    But what about first rebind(). It does not work too.
    When I try call rebind() on Grid1 and Grid2, both work wrong.

    Krzysztof
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Nov 2008 Link to this post

    Hi Krzysztof,

    How the grid is bound in your case? NeedDataSource, DataSourceID? Do you have any ajax (RadAjaxManager, RadAjaxPanel)?

    Regards,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Krzysztof
    Krzysztof avatar
    29 posts
    Member since:
    Aug 2008

    Posted 25 Nov 2008 Link to this post

    Hi

    Both grids are in RadAjaxPanel.

    I get data like :
    protected void Grid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        { 
            DataSet data = new DataSet();
            data = getDataSetFunction();
            Grid.DataSource = dataSet;   
        }

    In the mean tile I found the solution but I do not like it.
    I made JavaScript timer like :

    var timerID = 0;
    var ii = 0 ;

    function UpdateTimer()
    {
      if(timerID) {
          clearTimeout(timerID);
       }
     
      ii = ii + 1 ;
      if (ii == 1)
      {
        tableViewW = $find("Grid1").get_masterTableView();
        tableViewW.rebind();
      }
      if (ii == 2)
      {
        tableViewW = $find("Grid2").get_masterTableView();
        tableViewW.rebind();
      }
       
      timerID = setTimeout("UpdateTimer()", 2000);
     
      if (ii == 3)
      {
        clearTimeout(timerID);
        timerID  = 0;
      }
    }

    function StartRebind()
    {
      timerID  = setTimeout("UpdateTimer()", 2000);
    }


    It works properly but grid by grid.
    Is this possible to rebind all grids in the same time ??

    Regards
    Krzysztof
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Nov 2008 Link to this post

    Hello Krzysztof,

    If you want to use the client-side rebind() method to rebind the grids, then they will be rebound subsequently. Therefore I suggest that you ajaxify your grid with RadAjaxManager instead of RadAjaxPanel and perform the required update as below:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadGrid2">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
        function Rebind()  
        {  
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindGrids");  
        }  
        </script>  
    </telerik:RadCodeBlock> 
    protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)  
    {  
        if (e.Argument == "RebindGrids")  
        {  
            RadGrid1.Rebind();  
            RadGrid2.Rebind();  
        }  

    Thus you can rebind the grids in one call back.

    Give it a try and let me know if any issues arise.

    Best wishes,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017