Telerik的MVC电网ClientTemplate复选框最初不显示 [英] Telerik MVC Grid ClientTemplate checkbox not displayed initially

查看:157
本文介绍了Telerik的MVC电网ClientTemplate复选框最初不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常类似的问题,以设在这里的帖子:
<一href=\"http://stackoverflow.com/questions/4249736/telerik-grid-with-checkbox-checkbox-not-showing-up-when-the-grid-initially-pain\">Telerik网格复选框 - 复选框不显示当电网最初描绘

基本上,我有一个包含复选框的ClientTemplate列Telerik的MVC3剃须刀网格。当页面加载最初,该复选框是不存在的 - 相反,它就是我想要的复选框的值是。然而,当阿贾克斯被触发(如分组列在一起),复选框显示没有问题。

我真的不明白解决我上面粘贴的线程....所以也许这就是答案,我只是不知道如何调用网格的构造函数。这里的code我有:

research.cshtml

  @(Html.Telerik()。网格(模型)
    。名称(网格)
    .DataKeys(键=&GT; keys.Add(M = GT; m.MessageInformation.MessageGUID))
    .DataBinding(数据绑定= GT; databinding.Ajax()
        。选择(_ ViewMessages,结果)
        .Update(_ UpdateSelectedMessage,结果))
    .Columns(列=&GT;
                 {
                     columns.Bound(O =&GT; o.MessageInformation.MessageGUID)
                         .ClientTemplate(&LT;输入类型=复选框'ID ='chkMessage的名字='checkedRecords'值='&LT;#= MessageInformation.MessageGUID#&GT;/&gt;中)
                         .title伪(检查)
                         .WIDTH(50)
                         .HtmlAttributes(新{风格=文本对齐:中心});
                     columns.Bound(O =&GT; o.MessageInformation.MessageGUID).title伪(ID);
                     columns.Bound(O =&GT; o.MessageInformation.MessageReceivedDateTime).title伪(收稿日期)格式({0:D})。
                     columns.Bound(O =&GT; o.MessageInformation.MessageReceivedDateTime).title伪(收到时间),格式为({0:T】);
                     columns.Bound(O =&GT; o.MessageInformation.MedVAMessageTypeString).title伪(消息类型);
                     columns.Bound(O =&GT; o.MessageStatus).title伪(状态);
                     columns.Command(命令=方式&gt; commands.Edit()按钮类型(GridButtonType.Text))标题(编辑)。
                 })    .Editable(编辑= GT; editing.Mode(GridEditMode.PopUp))
    .Scrollable(SCROLLING =&GT; scrolling.Enabled(真))
    .Sortable(排序= GT; sorting.Enabled(真))
    .Pageable(分页=&GT; paging.Enabled(真))
    .Filterable(过滤=&GT; filtering.Enabled(真))
    .Groupable(分组=&GT; grouping.Enabled(真))
    .Footer(真)
    )

ResultsController.cs

  [GridAction]
        公众的ActionResult研究()
        {
            ViewBag.Message =研究;            返回查看(DataAccess.Get_Messages());
        }        [GridAction]
        公众的ActionResult _ViewMessages()
        {
            ViewBag.Message =研究;            返回查看(新GridModel(DataAccess.Get_Messages()));
        }


解决方案

您最初绑定到服务器的数据,所以你需要一个服务器模板以及一个客户端模板:

  @(Html.Telerik()。网格(模型)
    。名称(网格)
    .DataKeys(键=&GT; keys.Add(M = GT; m.MessageInformation.MessageGUID))
    .DataBinding(数据绑定= GT; databinding.Ajax()
        。选择(_ ViewMessages,结果)
        .Update(_ UpdateSelectedMessage,结果))
    .Columns(列=&GT;
                 {
                     columns.Bound(O =&GT; o.MessageInformation.MessageGUID)
                         .Template(MI =&GT; {
                             %GT;
                                 &LT;输入类型=复选框'ID ='chkMessage的名字='checkedRecords'值='&LT;%= mi.MessageGUID%GT;' /&GT;
                             %GT;
                         })
                         .ClientTemplate(&LT;输入类型=复选框'ID ='chkMessage的名字='checkedRecords'值='&LT;#= MessageInformation.MessageGUID#&GT;/&gt;中)
                         .title伪(检查)
                         .WIDTH(50)
                         .HtmlAttributes(新{风格=文本对齐:中心});
                     columns.Bound(O =&GT; o.MessageInformation.MessageGUID).title伪(ID);
                     columns.Bound(O =&GT; o.MessageInformation.MessageReceivedDateTime).title伪(收稿日期)格式({0:D})。
                     columns.Bound(O =&GT; o.MessageInformation.MessageReceivedDateTime).title伪(收到时间),格式为({0:T】);
                     columns.Bound(O =&GT; o.MessageInformation.MedVAMessageTypeString).title伪(消息类型);
                     columns.Bound(O =&GT; o.MessageStatus).title伪(状态);
                     columns.Command(命令=方式&gt; commands.Edit()按钮类型(GridButtonType.Text))标题(编辑)。
                 })    .Editable(编辑= GT; editing.Mode(GridEditMode.PopUp))
    .Scrollable(SCROLLING =&GT; scrolling.Enabled(真))
    .Sortable(排序= GT; sorting.Enabled(真))
    .Pageable(分页=&GT; paging.Enabled(真))
    .Filterable(过滤=&GT; filtering.Enabled(真))
    .Groupable(分组=&GT; grouping.Enabled(真))
    .Footer(真)
    )

I have a very similar problem to the post located here: Telerik grid with checkbox - Checkbox not showing up when the grid initially paints

Basically, I have a telerik MVC3 razor grid with a ClientTemplate column that consists of a checkbox. When the page loads initially, the checkbox is not there - instead it is what I want the value of the checkbox to be. However, when ajax is fired (such as grouping columns together), the checkbox shows with no problem.

I don't really understand the solution to the thread I pasted above....so maybe that is the answer and I just don't know how to call the grid's constructor. Here's the code I have:

research.cshtml

@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(keys => keys.Add(m => m.MessageInformation.MessageGUID))
    .DataBinding(databinding => databinding.Ajax()
        .Select("_ViewMessages", "Results")
        .Update("_UpdateSelectedMessage", "Results"))
    .Columns(columns =>
                 {
                     columns.Bound(o => o.MessageInformation.MessageGUID)
                         .ClientTemplate("<input type='checkbox' id='chkMessage' name='checkedRecords' value='<#= MessageInformation.MessageGUID #>' />")
                         .Title("Check")
                         .Width(50)
                         .HtmlAttributes(new { style = "text-align:center" });
                     columns.Bound(o => o.MessageInformation.MessageGUID).Title("ID");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Date").Format("{0:d}");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Time").Format("{0:t}");
                     columns.Bound(o => o.MessageInformation.MedVAMessageTypeString).Title("Message Type");
                     columns.Bound(o => o.MessageStatus).Title("Status");
                     columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Text)).Title("Edit");
                 })

    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Scrollable(scrolling => scrolling.Enabled(true))
    .Sortable(sorting => sorting.Enabled(true))
    .Pageable(paging => paging.Enabled(true))
    .Filterable(filtering => filtering.Enabled(true))
    .Groupable(grouping => grouping.Enabled(true))
    .Footer(true)
    )

ResultsController.cs

        [GridAction]
        public ActionResult Research()
        {
            ViewBag.Message = "Research";

            return View(DataAccess.Get_Messages());
        }

        [GridAction]
        public ActionResult _ViewMessages()
        {
            ViewBag.Message = "Research";

            return View(new GridModel(DataAccess.Get_Messages()));
        }

解决方案

You are initially binding to server data so you will need a server template as well as a client template:

@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(keys => keys.Add(m => m.MessageInformation.MessageGUID))
    .DataBinding(databinding => databinding.Ajax()
        .Select("_ViewMessages", "Results")
        .Update("_UpdateSelectedMessage", "Results"))
    .Columns(columns =>
                 {
                     columns.Bound(o => o.MessageInformation.MessageGUID)
                         .Template(mi => {
                             %>
                                 <input type='checkbox' id='chkMessage' name='checkedRecords' value='<%= mi.MessageGUID %>' />
                             %>
                         })
                         .ClientTemplate("<input type='checkbox' id='chkMessage' name='checkedRecords' value='<#= MessageInformation.MessageGUID #>' />")
                         .Title("Check")
                         .Width(50)
                         .HtmlAttributes(new { style = "text-align:center" });
                     columns.Bound(o => o.MessageInformation.MessageGUID).Title("ID");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Date").Format("{0:d}");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Time").Format("{0:t}");
                     columns.Bound(o => o.MessageInformation.MedVAMessageTypeString).Title("Message Type");
                     columns.Bound(o => o.MessageStatus).Title("Status");
                     columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Text)).Title("Edit");
                 })

    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Scrollable(scrolling => scrolling.Enabled(true))
    .Sortable(sorting => sorting.Enabled(true))
    .Pageable(paging => paging.Enabled(true))
    .Filterable(filtering => filtering.Enabled(true))
    .Groupable(grouping => grouping.Enabled(true))
    .Footer(true)
    )

这篇关于Telerik的MVC电网ClientTemplate复选框最初不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆