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

[Solved] columns template re-binding.

1 Answer 55 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 01 Nov 2011, 07:32 PM
Hi,
I' ve trying to rebind a grid that I have with columns template, the column display a partial view, but I can't get the grid to update its data. The update of the grid is based on other fields on the view.
How can I make this?

Here is the view
 <script type="text/javascript">

        function ComboBoxClients_onChange(e) {
            var combobox_client = $('#ComboBox_Client').data('tComboBox');
            var value = combobox_client.value();
        }

        $(document).ready(function () {
            $("#ApplyFilter_Btn").click(function () {
                var combobox_client = $("#ComboBox").data("tComboBox");
                var value_client = combobox_client.value();
                var grid = $("#PermissionsGrid").data("tGrid");
                var value_user = $('#ComboBox_User').data('tAutoComplete');

                               $.ajax({
                                type: "GET",
                                url: "<%= Url.Action("GetPermissionsForClient", "PermissionsSetting") %>",
                                data: ({'c_id': value_client, 'u_list' : value_user.value()}),
                                dataType: "json",
                                success: function (d) {
                                    if ($.isEmptyObject(d)) {
                                        return;
                                    }
                                    if (!d.Result) {
                                        alert(d.ErrorMessage[0].ErrorMessage);
                                    }
                                    else {
                                           grid.rebind(d.Data);
                                    }
                                    return;
                                    }
                                });
            });
        });

     </script>

<div class="filter_header">
            <div class="column1">
                <label>Client</label><% Html.RenderAction("ShowList", "ClientList"); %>
            </div>
            <div class="column2">
                <label for="ComboBox_User">
                    User
                </label>
                <% Html.Telerik().AutoComplete()
                            .Name("ComboBox_User")
                            .BindTo(Model.UserList.Select(u => u.Text))
                            .Filterable(filtering =>
                            {
                                filtering.FilterMode(AutoCompleteFilterMode.StartsWith);
                            })
                            .Multiple(multi =>
                            {
                                multi.Separator(",")
                                     .Enabled(true);

                            })
                            .HtmlAttributes(new { @class = "user_list" })
                            .Render();
                %>
            </div>
            <button class="t-button t-button-icontext" type="button" id="ApplyFilter_Btn">
                <span class="t-icon t-refresh"></span>Apply Filters</button>
        </div>
<% Html.Telerik().Grid<Models.ClientPermissions>()
                                        .Name("PermissionsGrid")
                                        .BindTo(Model.ForUpdatePermissions)
                                        .Columns(col =>
                                        {
                                            col.Bound(o => o.ClientName).Title("Client");
                                            col.Template(o =>
                                            {
            %>
            <%                                       Html.RenderPartial("CreateGrid", o);
                                            })
                                            .ClientTemplate(
                                                "<table><tr><td>" + "<#= ClientName #></td>" +
                                                "<td><table><tr><td><input type='hidden' value='" + "<#= UserAdId #>" + "/>" +
                                                "<input type='checkbox' name='DownloadAccessChecked' checked='" + "<#= DownloadAccess #>" + " /> " +
                                                "</td><td><input type='checkbox' name='UploadAccessChecked' checked='" + "<#= UploadAccess #>" + "/>" +
                                                "</td><td><input type='checkbox' name='NotifyDownloadChecked' checked='" + "<#= GetNotifyStatus() #>" + "/>" +
                                                "</td><td><input type='checkbox' name='NotifyUploadChecked' checked='" + "<#= GetNotifyStatus() #>" + "/>" +
                                                "</td></tr></table>"
                                                    )
                                            .HeaderTemplate(() =>
                                            {
            %>
            <strong>Effective Permissions for Group:
                <%= Html.Encode(Model.ManagedGroupDesc)%></strong>
            <%
                                            });
                                        })
                                         .DataBinding(d => d.Ajax().Select("GetPermissionsForClient", "PermissionsSetting"))
                                         .Footer(false)
                                         .Render();
            %>

The partial view renders a grid itself:
<% Html.Telerik().Grid<Models.UserPermissions>()
                .Name("Grid")
                .EnableCustomBinding(true)
                .BindTo(Model.EffectiveClientPermissions)
                .Columns(col =>
                {
                    col.Bound(o => o.UserName).Title("User");
                    col.Template(o =>
                    {
%>
<table cellspacing="0" class="data-row">
    <tr>
        <td>
            <input type="hidden" value=" <%= Html.Encode(o.UserAdId) %>" />
            <input type="checkbox" name="DownloadAccessChecked" checked="<%= Html.Encode(o.DownloadAccess) %>" />
        </td>
        <td>
            <input type="checkbox" name="UploadAccessChecked" checked="<%= Html.Encode(o.UploadAccess)%> " />
        </td>
        <td>
            <input type="checkbox" name="NotifyDownloadChecked" checked="<%= Html.Encode(o.GetNotifyStatus())%> " />
        </td>
        <td>
            <input type="checkbox" name="NotifyUploadChecked" checked="<%= Html.Encode(o.GetNotifyStatus())%> "/>
        </td>
    </tr>
</table>
<%
                    }).Width(270)
                    .HeaderTemplate(() =>
                    { %>
<table cellspacing="0" class="data-header">
    <tr>
        <td colspan="2" align="center">
            <strong>Access</strong>
        </td>
        <td colspan="2" align="center">
            <strong>Notification</strong>
        </td>
    </tr>
    <tr>
        <td>
            Download
        </td>
        <td>
            Upload
        </td>
        <td>
            Download
        </td>
        <td>
            Upload
        </td>
    </tr>
</table>
<% })
                    .HeaderHtmlAttributes(new { style = "text-align:center" })
                    .HtmlAttributes(new { style = "text-align:center" })
                    .Width(270);
                })
                .Footer(false)
                .Render();
     
%>
 
And the controller method:
[GridAction]
       [RequiresAuthentication]
       public JsonResult GetPermissionsForClient(short? c_id, string u_list)
       {
           JsonResult result;
           short client_id;
           short bg_id = Repository.GetUserBusinessGroup(AuthenticationService.GetAuthenticatedUserName()).Business_Group_ID;
           if (c_id.HasValue && c_id != null)
           {
               client_id = (short)c_id;
               string[] user_list = u_list.ToString().Split(',');
               result = Json(new GridModel<ClientPermissions>
               {
                   Data = new List<ClientPermissions> { GetPermissionsforClient(client_id, bg_id, user_list) }
               });
           }
           else result = Json(new GridModel { Data = "" });
           return Json(result, JsonRequestBehavior.AllowGet);
       }

The grid renders fine with the server data, but I can't get to rebind it with the json object, I' ve also tried with an action method, not returning a json result, but no sucess either, I am not sure if the client template is well defined.

Any help that can point me in the right direction......

Thanks,




1 Answer, 1 is accepted

Sort by
0
Laura
Top achievements
Rank 1
answered on 03 Nov 2011, 08:04 PM
Hi,

I changed the code, added client template to the partial view :
Html.Telerik().Grid<FtpApp.Models.UserPermissions>()
                .Name("Grid")
                .EnableCustomBinding(true)
                .BindTo(Model.EffectiveClientPermissions)
                .DataBinding(d => d.Ajax().Select("CreateGrid", "PermissionsSetting" ))
                .Columns(col =>
                {
                    col.Bound(o => o.UserName).Title("User");
                    col.Template(o =>
                    {
%>
<table cellspacing="0" class="data-row">
    <tr>
        <td>
            <input type="hidden" value=" <%= Html.Encode(o.UserAdId) %>" />
            <input type="checkbox" name="DownloadAccessChecked" checked="<%= Html.Encode(o.DownloadAccess) %>" />
        </td>
        <td>
            <input type="checkbox" name="UploadAccessChecked" checked="<%= Html.Encode(o.UploadAccess)%> " />
        </td>
        <td>
            <input type="checkbox" name="NotifyDownloadChecked" checked="<%= Html.Encode(o.GetNotifyStatus())%> " />
        </td>
        <td>
            <input type="checkbox" name="NotifyUploadChecked" checked="<%= Html.Encode(o.GetNotifyStatus())%> "/>
        </td>
    </tr>
</table>
<%
                    })
                    .Width(270)
                    .ClientTemplate(
                                    "<table><tr><td><input type='hidden' value='" + "<#= UserAdId #>" + "/>" + " <#= UserName #>" + "/td>" +
                                    "<td><input type='checkbox' name='DownloadAccessChecked' checked='" + "<#= DownloadAccess #>" + " /> " +
                                    "</td><td><input type='checkbox' name='UploadAccessChecked' checked='" + "<#= UploadAccess #>" + "/>" +
                                    "</td><td><input type='checkbox' name='NotifyDownloadChecked' checked='" + "<#= GetNotifyStatus() #>" + "/>" +
                                    "</td><td><input type='checkbox' name='NotifyUploadChecked' checked='" + "<#= GetNotifyStatus() #>" + "/>" +
                                    "</td></tr></table>"
                                    )
                    .HeaderTemplate(() =>
                    { %>
<table cellspacing="0" class="data-header">
    <tr>
        <td colspan="2" align="center">
            <strong>Access</strong>
        </td>
        <td colspan="2" align="center">
            <strong>Notification</strong>
        </td>
    </tr>
    <tr>
        <td>
            Download
        </td>
        <td>
            Upload
        </td>
        <td>
            Download
        </td>
        <td>
            Upload
        </td>
    </tr>
</table>
<% })
                    .HeaderHtmlAttributes(new { style = "text-align:center" })
                    .HtmlAttributes(new { style = "text-align:center" })
                    .Width(270);
                })
                .Footer(false)
                .Render();
     
%>
 
But I don't know how to add a client template to the column where the partial view is rendered, I tried with the table that the partial view will rendered but I got an error saying that the data was not available:

<script type="text/javascript">
 
        $(document).ready(function () {
           $("#ApplyFilter_Btn").click(function () {
               var combobox_client = $("#ComboBox").data("tComboBox");
               var value_client = combobox_client.value();
               var value_user = $('#ComboBox_User').data('tAutoComplete');
               var grid = $("#PermissionsGrid").data("tGrid");
               grid.ajax.selectUrl = '/PermissionsSetting/GetPermissionsForClient?c_id=' + value_client + '&u_list=' + value_user.value();
               grid.ajaxRequest();
               grid.rebind();
           });
       });
 
       var first = true;
       function PermissionsGrid_onBinding(e) {
           if (first) {
               e.preventDefault();
               first = false;
           }
       }
   </script>
    
   <div class="columns">
       <% if ((Model != null) && (Model.ForUpdatePermissions.Count() > 0))
          {  %>
       <div class="bot_line">
           <p class="b_text">
               User Permissions</p>
       </div>
       <!-- START UPDATE PERMISSIONS PANE -->
       <div class="filter_header">
           <div class="column1">
               <label for="ComboBox">Client</label><% Html.RenderAction("ShowList", "ClientList"); %>
           </div>
           <div class="column2">
               <label for="ComboBox_User">
                   User
               </label>
               <% Html.Telerik().AutoComplete()
                           .Name("ComboBox_User")
                           .BindTo(Model.UserList.Select(u => u.Text))
                           .Filterable(filtering =>
                           {
                               filtering.FilterMode(AutoCompleteFilterMode.StartsWith);
                           })
                           .Multiple(multi =>
                           {
                               multi.Separator(",")
                                    .Enabled(true);
 
                           })
                           .HtmlAttributes(new { @class = "user_list" })
                           .Render();
               %>
           </div>
           <button class="t-button t-button-icontext" type="button" id="ApplyFilter_Btn">
               <span class="t-icon t-refresh"></span>Apply Filter</button>
       </div>
       <%-- <% } %>--%>
       <div class="clear">
           <br />
           <br />
       </div>
       <div class="update_panel">
           <div class="bot_line">
               <p class="b_text">
                   Update Permissions</p>
           </div>
           <br />
           <% Html.Telerik().Grid<FtpApp.Models.ClientPermissions>()
                                       .Name("PermissionsGrid")
                                       .BindTo(Model.ForUpdatePermissions)
                                       .Columns(col =>
                                       {
                                           col.Bound(o => o.ClientName).Title("Client");
                                           col.Template(o =>
                                           {
           %>
           <%                                       Html.RenderPartial("CreateGrid", o);
                                           })                                                                     
                                           .ClientTemplate(" ???????" )
                                           .HeaderTemplate(() =>
                                           {
           %>
           <strong>Effective Permissions for Group:
               <%= Html.Encode(Model.ManagedGroupDesc)%></strong>
           <%
                                           });
                                       })
                                        .DataBinding(d => d.Ajax().Select("GetPermissionsForClient", "PermissionsSetting"))
                                        .Footer(false)
                                        .Render();
           %>
           <br />
           <div class="one_button">
               <input type="submit" class="t-button" value="Update" />
           </div>
           <div class="clear">
           </div>
       </div>

The grid on the view is updated with the value from the filters, but the column where the partial view is rendered appears empty.

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