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

[Solved] Grid data is not refreshing after ajax binding.

0 Answers 37 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.
Laura
Top achievements
Rank 1
Laura asked on 22 Jun 2011, 09:28 PM
Hi,
I think I am missing something here, but I don't know what it is, so any help will be appreciated.
I have a Combo Box and a grid with a template column that renders a partial view with another grid.
<label for="ComboBox_Client">
              Client
          </label>
          <% Html.Telerik().ComboBox()
                              .Name("ComboBox_Client")
                              .ClientEvents(events => events.OnChange("ComboBoxClient_onChange"))
                              .BindTo((IEnumerable<DropDownItem>)Model.ClientList)
                              .SelectedIndex(-1)
                              .Render();
          %>
      </div>
      <br />
      <br />
      <% Html.Telerik().Splitter()
              .Name("LayoutSplitter")
              .Orientation(SplitterOrientation.Vertical)
              .Panes(panes =>
              {
                  panes.Add()
                      .Size("350px")
                      .Resizable(false)
                      .Scrollable(true)
                      .Content(() =>
                          
      %>
      <!-- START UPDATE PERMISSIONS PANE -->
      <p class="b_text">
          Update Permissions</p>
      <br />
      <% Html.Telerik().Grid(Model.ExternalPermissions)
                                      .Name("PermissionsGrid")
                                      .BindTo(Model.ExternalPermissions)
                                      .Columns(col =>
                                      {
                                          col.Bound(o => o.EntityName).Title("Entity");
                                          col.Template(o =>
                                          {
      %>
      <%                                       Html.RenderPartial("CreateGrid", o);
                                          })
                                          .ClientTemplate("<label class='input'> <#= EntityName #> </label> <#= EffectivePermissions.ToString() #>")
                                          .HeaderTemplate(() =>
                                          {
      %>
                                                  <strong>WhatEver</strong>
      <%
                                          });
                                      })
                                      .DataBinding(binding => binding.Ajax().Select("GetPermissionsForClient", "PermissionsSetting"))
                                      .ClientEvents(events => events.OnDataBinding("PermissionsGrid_onBinding"))
                                      .Footer(false)
                                      .Render();

On the OnChange event of the combo box (ComboBox_Client) I execute the rebind of the grid:
function ComboBoxClient_onChange(e) {
            var combobox = $('#ComboBox_Client').data('tComboBox');
            var value = combobox.value();
 
            $("#PermissionsGrid").data("tGrid").rebind({
                c_id: value
            });
        }
 And the method in the controller:
[GridAction]
       public JsonResult GetPermissionsForClient(Int16? c_id)
       {
           short client_id = 0;
           JsonResult result;
           if (c_id.HasValue && c_id != null)
           {
               client_id = (short)c_id;
               string u_id = AuthenticationService.GetAuthenticatedUserName();
               result = Json(new GridModel<EntityPermissions>
               {
                   Data = new List<EntityPermissions> { PermissionsManager.GetPermissionsforClient(client_id, u_id) }
               });
           }
           else result = Json(new GridModel { Data = ""});
           return result;
       }

When the page is executed the grid is populated using server binding:
public ActionResult ExternalPermissionsUpdate()
        {
            string u_id = AuthenticationService.GetAuthenticatedUserName();
            SettingPermissionsModel permissionModel = new SettingPermissionsModel();
            permissionModel.ClientList = GetClientListForDisplay(u_id);
            permissionModel.UserList = GetUserListForDisplay(u_id);
                         
            //Permissions x User
             
            foreach (var client in permissionModel.ClientList)
            {
                Int16 c_id = Convert.ToInt16(client.Value);
                permissionModel.ExternalPermissions.Add(PermissionsManager.GetPermissionsforClient(c_id, u_id));
            }
                         
            ViewData.Model = permissionModel;
            return View("ExternalPermissionsUpdate");
        }

The grid populates with the correct data, when the OnChange event of the combo box is raised, the method GetPermissionsForClient is executed and the data is returned to the client, but the grid is not refreshed, it continues showing the old values.
What I am missing/wrong?

Thanks.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Share this question
or