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

Rebinf two grids in JavaScript

5 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krzysztof
Top achievements
Rank 1
Krzysztof asked on 25 Nov 2008, 10:47 AM
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

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 25 Nov 2008, 01:00 PM
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.
0
Krzysztof
Top achievements
Rank 1
answered on 25 Nov 2008, 02:12 PM
OK.
But what about first rebind(). It does not work too.
When I try call rebind() on Grid1 and Grid2, both work wrong.

Krzysztof
0
Vlad
Telerik team
answered on 25 Nov 2008, 04:48 PM
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.
0
Krzysztof
Top achievements
Rank 1
answered on 25 Nov 2008, 05:05 PM
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
0
Iana Tsolova
Telerik team
answered on 28 Nov 2008, 08:23 AM
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.
Tags
Grid
Asked by
Krzysztof
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Krzysztof
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or