将行模板应用于网格

时间:2013-04-06 18:08:41

标签: kendo-grid

我试图将行模板应用于网格,但数据未显示... 在我自定义之后,我开始使用一个非常简单的模板。

到目前为止我所拥有的:

@(Html.Kendo().Grid<MyProject.Models.StudentCF>().
Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.FirstName);
    columns.Bound(p => p.LastName);
    columns.Bound(p => p.Age);
    columns.Bound(p => p.Course);
    columns.Bound(p => p.School.Name);
})
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("IndexJsonCF", "StudentCF"))
)
.Selectable()
.AutoBind(true)
.Filterable()
.Groupable()
.Sortable()
.Pageable(pager =>
{
    pager.Input(true);
    pager.Messages(messages => messages.Display("Showing items from {0} to {1}. Total items: {2}"));
    pager.PageSizes(new int[]{5,10,20,50,100,1000});
    pager.Refresh(true);
})
.ClientRowTemplate("rowtemplate")
)

<script type="text/x-kendo-template" id="rowtemplate">
    "<tr>" +
        "<td>" +
           "#= FirstName#" +
        "</td>" +
        "<td>" +
           "#= LastName#" +
        "</td>" +
        "<td>" +
            "#= Age#" +
        "</td>" +
        "<td>" +
            "#= Course#" +
        "</td>" +
        "<td>" +
            "#= School.Name#" +
        "</td>" +
     "</tr>" 
</script>

网格中显示的内容只是一行,其中包含模板rowtemplate的ID(重复)

我错过了什么?

更新 我想做这样的事情:ClientRowTemplate(),但似乎这是不可能的......

1 个答案:

答案 0 :(得分:0)

以下是将行模板应用于网格但确保FirstName等字段有效的代码。所以只需在此处删除字符串,然后编写简单的HTML。

<script type="text/x-kendo-template" id="rowtemplate">
<tr>
    <td>
       #= FirstName#
    </td>
    <td>
       #= LastName#
    </td>
    <td>
        #= Age#
    </td>
    <td>
        #= Course#
    </td>
    <td>
        #= School.Name#
    </td>
 </tr> 
 </script>
相关问题