Telerik MVC Grid ClientTemplate checkbox not displayed initially

后端 未结 3 1332
夕颜
夕颜 2021-01-19 07:06

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 teler

相关标签:
3条回答
  • 2021-01-19 07:20

    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)
        )
    
    0 讨论(0)
  • 2021-01-19 07:21

    @McGarnagle's syntax doesn't work for me. Here's mine that works:

    .Template(@<text><input name="chkStatus" type="checkbox" @(item.Status ? "checked=\"checked\"" : "") disabled /></text>)
    .ClientTemplate("<input type='checkbox' name='chkStatus' value='<#= Status #>' <#=Status?'checked':''#> disabled  />")
    
    0 讨论(0)
  • 2021-01-19 07:30

    Another snippet for Razor syntax: CheckBox can editable after click edit.

    .Template(
            @<text>
                <input name="chkStatus" type="checkbox" @if(item.Status) { @:checked="checked" } disabled /> 
            </text>
             )
    .ClientTemplate("<input type='checkbox' name='chkStatus' value='<#= Status #>' <#=Status?'checked':''#> disabled  />");
    
    0 讨论(0)
提交回复
热议问题