JavaScript中的headerTemplate而不是Kendo-UI Grid的Wrapper

时间:2012-12-17 14:33:43

标签: kendo-ui

如何在javascript中编写此代码而不是使用MVC Wrapper?

@(Html.Kendo().Grid(Model.List)
      .Name("grid")
    .Columns(c => { 
        c.Bound(e => e.ID); 
        c.Bound(e => e.Nom).HeaderHtmlAttributes(new { colspan = 2 }); 
        c.Bound(e => e.Nb).HeaderHtmlAttributes(new { style= "display:none;" }); 
    })
)

我开始使用以下代码进行实验,我知道这不是一个确切的问题 匹配上面提到的属性,但我该如何设置 HeaderHtmlAttributes和Headertemplate for the javascript for the Kendo grid?

$("div#kendogrid").kendoGrid({
        dataSource: dataSource,
        columns: [
             {
                 field: "ID",
                 title: "Nr Id",
                 headerTemplate: "sample template text col 1",
                 width: 100
             },
             {
                 field: "Nom",
                 headerAttributes: {
                     "class": "myHeader",
                     style: "text-align: right"
                 },
                 width: 200
             }
        ]
    });

1 个答案:

答案 0 :(得分:4)

您是对的,HeaderHtmlAttributes是使用columns.headerAttributes指定的,而HeaderTemplate的等价物是columns.headerTemplate。请参阅文档链接:

原始代码的翻译将是:

$("#kendogrid").kendoGrid({
    dataSource: dataSource,
    columns   : [
        {
            field: "ID"
        },
        {
            field           : "Nom",
            headerAttributes: {
                colspan: 2
            }
        },
        {
            field           : "Nb",
            headerAttributes: {
                style: "display:none"
            }
        }
    ]
});