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

Does client side rebind work with NeedDatasource?

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 11 Dec 2014, 04:03 PM
Hi,

Just for tests I put a button on my page and used the code below but it does not seem to cause  a postback of refetch of data using NeedDataSource in code-behind?

function refresh() {
    var masterTable = $find("<%= grdUsers.ClientID %>").get_masterTableView();
    masterTable.rebind();
}

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 16 Dec 2014, 09:20 AM
Hello Al,

The behavior that you are describing is rather unexpected. Can you please ensure that your button is not initiating postback, which could prevent the grid to fire its command.

Following is a very basic demonstrating of the functionality that you are requesting, which works as expected on my end:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function refreshGrid(sender, args) {
            var grid = $find("<%=RadGrid1.ClientID%>");
            var masterTable = grid.get_masterTableView();
            masterTable.rebind();
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
</telerik:RadGrid>
 
<telerik:RadButton runat="server" Text="Refresh" OnClientClicked="refreshGrid" AutoPostBack="false"></telerik:RadButton>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("Id", typeof(int));
    table.Columns.Add("Description", typeof(string));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "Description");
    }
 
    (sender as RadGrid).DataSource = table;
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 17 Dec 2014, 02:12 PM
Thanks Konstantin - your code is exactly what I was doing, I can't explain it but without changing anything the rebind is now working just fine.
Tags
Grid
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Konstantin Dikov
Telerik team
Al
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or