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

Grid rebind() single param not working

8 Answers 276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gabe Calabria
Top achievements
Rank 1
Gabe Calabria asked on 15 Mar 2010, 09:27 PM
Basically, I want to trigger the grid to rebind on a javascript call.
When the javascript method fires, it does trigger the action but the param id is always set to what the initial value was.
When I look at the action's param string id in the debugger, the value doesnt correspond to what the alert(orderId) shows me.
Did I miss something?

Using MVC 1.0 and Telerik 2009.3.1223.135

View


 <% Html.Telerik().Grid<Order>() 
                        .Ajax(ajax => ajax.Action("AjaxTest""Home"new { id = Model.OrderID.ToString()})) 
                        .BindTo(Model.Orders) 
                        .Name("ordersGrid").PrefixUrlParameters(false
                        .AssetKey("ordersAssetGroup"
                        .Columns(columns => 
                        { 
                            columns.Add(t => t.FirstName).Title("First Name"); 
                            columns.Add(t => t.LastName).Title("Last Name"); 
                        }) 
                        .Scrollable(scrolling => scrolling.Height(150)) 
                        .Render(); 
                        
                        %> 

Action

[GridAction] 
        public ActionResult AjaxTest(string id) 
        { 
            return View(new GridModel<Order> 
            { 
                Data = this.orderService.GetOrderById(id) 
            }); 
        } 

Javascript call to rebind

function rebindGrid(orderId) { 
    alert(orderId); // just to be sure my id is changing like it should
    var grid = $('#orderGrid').data('tGrid'); 
    grid.rebind({id:orderId}); 


8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Mar 2010, 08:41 AM
Hi Gabe Calabria,

I suggest you try upgrading to the latest official release 2010.1.309. I believe this problem is fixed there.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Derk-Jan Sevink
Top achievements
Rank 1
answered on 16 Apr 2010, 02:07 PM
I'm having the same problem here with the latest version.

view:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"
    <script type="text/javascript"
        function onRowSelected(e) { 
            var sourceGrid = $('#Source').data('tGrid'); 
            var themePageId = e.row.cells[0].innerHTML; 
 
            $('#themePageId').text(themePageId); 
 
            sourceGrid.rebind({ 
                id: themePageId 
            }); 
        } 
    </script> 
 
    <h2>Index</h2> 
 
    <%= Html.Telerik().Grid((IEnumerable<KennisModel.Data.ThemePage>)ViewData["themepages"]) 
        .Name("ThemePage") 
        .Columns(columns => 
        { 
            columns.Bound(o => o.themepage_id).Width(50); 
            columns.Bound(o => o.name).Width(500); 
        }) 
        .Scrollable() 
        .Sortable() 
        .Pageable() 
        .Selectable() 
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectionClientSide_ThemePage", "ThemePage")) 
        .ClientEvents(events => events.OnRowSelected("onRowSelected")) 
         
    %> 
    <h3>Themepage (<span id="themePageId"><%= ViewData["themepageid"]%></span>)</h3> 
    <%= Html.Telerik().Grid((IEnumerable<KennisModel.Data.Source>)ViewData["sources"]) 
        .Name("Source") 
        .Columns(columns => 
        { 
            columns.Bound(o => o.source_id).Width(50); 
            columns.Bound(o => o.name).Width(500); 
        }) 
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectionClientSide_Source", "ThemePage", new { id = (string)ViewData["themepageid"] })) 
    %> 
 
    <p> 
        <%= Html.ActionLink("Create New", "Create") %> 
    </p> 
 
</asp:Content> 


</asp:Content> controller:
[GridAction] 
    public ActionResult _SelectionClientSide_Source(string id) 
    {.... 

the string "id" is always the initial value.
it should be the value of the parent grid.

looks like the same problem as the original author has.

can't find the solution after a days work......

0
chris
Top achievements
Rank 1
answered on 25 Sep 2010, 02:07 PM
Is grid.rebind still broken?

I am using version 2010.2.825.235

During debugging the client side script passes the parameter to the action, the action retrieves the data, the action returns the data but the grid does not show the data and instead just shows the busy animation (in the bottom left of the grid).

VIEW
<%= Html.Telerik().Grid<SDAC.Models.vResult>()
                .Name("Grid")
                .DataKeys(keys =>
                {
                    keys.Add(p => p.idresult);
                })
 
                .DataBinding(dataBinding =>
                {
                    dataBinding.Ajax()
                        .Select("_Select", "Results");
                })
                .Columns(columns =>
                {
                    columns.Bound(o => o.Runner);
                    columns.Bound(o => o.Race);
                    columns.Bound(o => o.Finish).Format("{HH:mm:ss}");
                    columns.Bound(o => o.Pace).Format("{HH:mm:ss}");
                    columns.Bound(o => o.Cat).Width(40);
                    columns.Bound(o => o.Ag).Width(100);
 
                })
            .Editable(editing => editing.Mode(mode))
            .Scrollable(scrolling => scrolling.Enabled(false))
            .Sortable(sorting => sorting.Enabled(true))
            .Pageable(paging => paging.PageSize(10))
            .Filterable(filtering => filtering.Enabled(true))
            .Groupable(grouping => grouping.Enabled(true))
            .Footer(true)
            %>

SCRIPT
<script type="text/javascript">
 
                function onRacesListChange(e) {
                    var racesList = $('#RaceDropDownList').data('tDropDownList');
                    var grid = $('#Grid').data('tGrid');
                    grid.rebind({ idrace: racesList.value() });
                }
 
            </script>

CONTROLLER ACTION

[GridAction]
public ActionResult _Select(int? idrace)
{
    if (!idrace.HasValue) { idrace = -1; }
    int id =(int) idrace;
 
    return View(new GridModel (Repo.GetAllResultsByRace(id)));
}

Is there a solution to this problem?

Thanks!!!!!
0
chris
Top achievements
Rank 1
answered on 26 Sep 2010, 08:50 PM
I have found my issue.. in case anyone else may fall over it.
It was the column formatting that killed the grid.

Wrong :
columns.Bound(p => p.Pace).Format("{HH:mm:ss}");

Right:
columns.Bound(p => p.Pace).Format("{0:HH:mm:ss}");
0
Diiimo
Top achievements
Rank 1
answered on 11 Jan 2011, 08:53 PM
Hello,

i'm having the same problem here with version 2011.1.1116.235 and CustomBinding.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>
  
<script type="text/javascript">
    $(function () {
        $("#physicians").change(function () {
            alert($(this).val());
            var g = $('#physicianGrid').data('tGrid');
            g.rebind({ id: $(this).val() });
        });
    });
</script>
<div class="editor-field">
    <%= Html.DropDownList( "physicians" )%> 
 </div>
  
<% Html.Telerik().Grid<BookingViewModel>()
        .Name( "physicianGrid" )
        .DataKeys( k => k.Add( m => m.MyId ).RouteKey( "MyId" ) )
        .DataBinding( d => d.Ajax().Select( "_SelectBookings", "MyController", new { area = "", id = ViewData["physicianId"] } ) )
        .Columns( c =>
        {
            c.Bound( m => m.ProjectName );
        } )
        .EnableCustomBinding( true )
        .Pageable( p => p.Total( ViewData["total"] != null ? ( int )ViewData["total"] : 0 ) )
        .ClientEvents( c => c.OnError( "onError" ) )
        .Render(); 
%>

[GridAction( EnableCustomBinding = true )]
public ActionResult _SelectPhysicianBookings( GridCommand command, int id )
{
}

The int "id" is always the initial value.
Is there any solution?

Regards,
Timo
0
Atanas Korchev
Telerik team
answered on 12 Jan 2011, 09:04 AM
Hi,

 The id parameter is "special" in ASP.NET MVC as it is included in the default route and the grid is using it. You can try changing the name of the parameter to any other value.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rajeev
Top achievements
Rank 1
answered on 25 Jul 2012, 06:41 PM
I got the same issue. I am using this code.
var tGrid = $("#SearchWindowGrid_Location").data('tGrid');
     tGrid.rebind({ partyId: e.ID});
0
Joe
Top achievements
Rank 2
answered on 10 Sep 2012, 07:01 PM
Darn.  I am also having the same problem.
I am using Telerik MVC Grid, the last version.
I have a stateful client page, with a backing store of a list of work item.
The user can click Next / Previous through the work item list.
Each time I use $.getJSON("",function (data) {}); to get the new data for the new work item.
Part of my logic includes a rebind of a Grid.  $('#myGrid').data("tGrid").rebind({ workItemId: newWorkItemId });
And just like the people above, each time I keep seeing the original values, not the new ones.
I have started noticing that the Toolbar Command buttons have anchor elements and I am using jQuery to update them, but the problems are all over the grid.  The column headers have anchor elements for the sorts to requery the controller.  The whole grid is just misbehaving.  It makes me want to drop the AJAX and go back the a full page POST.
There must be lots of people who need this capability.
Sincerely, Joe

Tags
Grid
Asked by
Gabe Calabria
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Derk-Jan Sevink
Top achievements
Rank 1
chris
Top achievements
Rank 1
Diiimo
Top achievements
Rank 1
Rajeev
Top achievements
Rank 1
Joe
Top achievements
Rank 2
Share this question
or