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

Using Template & ClientTemplate grid not populating after refresh or paging using AJAX

2 Answers 151 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.
Andy McShane
Top achievements
Rank 1
Andy McShane asked on 11 Jan 2011, 06:17 PM
Hi, I have been following the troubleshooter here

trying to work out why my grid is not working. I am using version 2010.3.1110 of the MVC controls and a grid with AJAX binding. I am also trying to use both a server side template and a client side template to build action links in my grid. I have got things working in so far as the initial loading of my grid which loads with data correctly using my server side template.

If I then try to page forward or refresh the grid I get the correct count of records still appearing at the bottom of grid but no data is actually being displayed. Am I missing a data binding call or something?

Here is the code I am using for my grid.

<% Html.Telerik().Grid(Model)
        .Name("UsersGrid")
        .BindTo(Model)
        .ToolBar(commands => commands.Custom().Text(ViewData["txtCreate"].ToString()).Action("SelectLicence", "Licence", new { height = 150, width = 350, modal = "true" }).HtmlAttributes(new { @class = "thickbox" }))
        .ToolBar(commands => commands.Custom().Text("Create Batch").Action("CreateBatch", "ServiceUser", new { height = 400, width = 400, modal = "true" }).HtmlAttributes(new { @class = "thickbox", @style = "float:right" }))
        .Columns(columns =>
        {
            columns.Bound(o => o.UserId)
                .Template(o =>
                              {
                               %>
                                 <%= Html.ActionLink("?????", "Edit", "ServiceUser_" + o.TreatmentId,
                                                     new { id = o.UserId, height = 600, width = 900, modal = "true" },
                                                     new { @class = "t-link action-edit thickbox" })
                                 %>
                               <%
                               })
                                .Encoded(false)
                                .Width(25)
                                .Sortable(false)
                                .Filterable(false)
                                .HtmlAttributes(new { @style = "text-align:center" })
                                .ClientTemplate("<a href='" + Url.Action("Edit", "ServiceUser_<# TreatmentID #>") + "/<# UserId #>|||||</a>")
                                .Title(" ");
 
            columns.Bound(o => o.UserId).Format(Html.ActionLink(ViewData["txtEdit"].ToString(), "Edit", "ServiceUser",
                                                                new { id = "{0}", height = 600, width = 900, modal = "true" },
                                                                new { @class = "t-link action-edit thickbox" }).ToString()).Title(" ").Encoded(false).Width(25)
                                                                                                                   .Sortable(false)
                                                                                                                   .Filterable(false)
                                                                                                                   .HtmlAttributes(new { @style = "text-align:center" });
 
            columns.Bound(o => o.UserId).Format(Html.ActionLink(ViewData["txtView"].ToString(), "Details", "ServiceUser",
                                                                new { id = "{0}", height = 600, width = 900, modal = "true" },
                                                                new { @class = "t-link action-edit thickbox" }).ToString()).Title(" ").Encoded(false).Width(25)
                                                                                                                   .Sortable(false)
                                                                                                                   .Filterable(false)
                                                                                                                   .HtmlAttributes(new { @style = "text-align:center" });
            columns.Bound(o => o.UserId).Format(Html.ActionLink(ViewData["txtPassword"].ToString(), "ResetPassword", "Account",
                                                                new { id = "{0}", height = 200, width = 500, modal = "true" },
                                                                new { @class = "t-link action-edit thickbox" }).ToString()).Title(" ").Encoded(false).Width(25)
                                                                                                                   .Sortable(false)
                                                                                                                   .Filterable(false)
                                                                                                                   .HtmlAttributes(new { @style = "text-align:center" });
            columns.Bound(o => o.UserName).Title(ViewData["txtUsername"].ToString());
            columns.Bound(o => o.UserFirstName).Title(ViewData["txtFirstname"].ToString());
            columns.Bound(o => o.UserSurname).Title(ViewData["txtSurname"].ToString());
            columns.Bound(o => o.UserEmail).Title(ViewData["txtEmail"].ToString());
            columns.Bound(o => o.ActivationCode).Title(ViewData["txtActivationCode"].ToString());
            columns.Bound(o => o.IsActive).Title(ViewData["txtActive"].ToString()).HtmlAttributes(new { @align = "center" });
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "ServiceUser"))
        .Filterable()
        .Pageable(paging => paging.PageSize(13))
        .Sortable()
        .Render();
%>

I have followed the troubleshooter and tried removing the initial
FROM:
 
<%= Html.Telerik().Grid(Model) // Model is IEnumerable<Order>
%>
 
 
<%= Html.Telerik().Grid<Order>() // No longer passing a datasource
%>
 
TO:
 
<%= Html.Telerik().Grid<Order>()
        .BindTo((IEnumerable<Order>)ViewData["Orders"])
%>
 
 
<%= Html.Telerik().Grid<Order>() // No longer calling the BindTo method
%>

This does not fix things. Any idea what I am doing wrong here?

2 Answers, 1 is accepted

Sort by
0
Andy McShane
Top achievements
Rank 1
answered on 12 Jan 2011, 05:01 PM
Andybody?
0
Uma
Top achievements
Rank 1
answered on 12 Jan 2011, 11:13 PM
Hi Andy,
I experienced the similar issue, but came to know that it was occured because of circular reference problem. Instead of hiding the reference in O/R mapping tool, i created ViewModel object for the original enitty and binded that object to grid instead of the original entity.

Give a try to this, this may helps.

Below Code is working in my case:(Grid with both server and client templates)
<% Html.Telerik().Grid<CommLetterTemplateViewModel>()
    .Name("DoosanGrid")
    .ToolBar(command => command.Custom().Text("Add New Template").Action("AddCommTemplate", "Admin"))
    .Columns(columns =>
        {
            columns.Bound(p => p.Name).Width(200);
            columns.Bound(p => p.Description).Width(300);
            columns.Bound(p => p.IsActive).ClientTemplate("<input type='checkbox' disabled='disabled' name='IsActive' <#= IsActive? checked='checked' : '' #> />").Width(100);
            columns.Bound(p => p.RelatedPlans).Width(200);
            columns.Template(r =>
                {%>
                        <% if (CommonHelpers.CanEditPaymentCycle(r.Id))
                           { %>
                                <%= Html.ActionLink("Edit", "UpdateCommTemplate", "Admin", new { Id = r.Id }, new { @class = "t-grid-action t-button t-state-default t-grid-edit" })%>   
                        <% } %>
                         
                 <%})
                         .ClientTemplate("<
a href='" + Url.Action("EditCommTemplate", "Admin", new { Id = "<#= Id #>" }) + "' class = 't-grid-action t-button t-state-default t-grid-edit' >Edit</a>" )
                    .Title("ACTIONS").Width(290);
            columns.Bound(p => p.Id).Hidden(true);
        })
     .DataBinding(bindings => bindings.Ajax().Select("_ManageCommTemplates", "Admin"))
     .Pageable(paging => paging.PageSize(25))
     .Sortable()
     .Selectable()
     .HtmlAttributes(new { style = "position:static" })
     .Render();
       
%>

Controller Action:
[GridAction]
public ActionResult _ManageCommTemplates()
{
    IEnumerable<CommLetterTemplateViewModel> list = CommTemplateRepository.GetCommLetterTemplatesList(CommonHelpers.GetCurrentPaymentCycleId());
    return View(new GridModel(list));           
}

Regards,
Uma
Tags
Grid
Asked by
Andy McShane
Top achievements
Rank 1
Answers by
Andy McShane
Top achievements
Rank 1
Uma
Top achievements
Rank 1
Share this question
or