2013-05-02 65 views
0

我希望能够利用数据属性来处理配置我的网格,但无法弄清楚如何为列设置groupHeaderTemplate如何使用数据属性为Kendo Grid列设置groupHeaderTemplate?

文档建议我用data-group-header-templatehttp://docs.kendoui.com/getting-started/data-attribute-initialization

<table id="grid" 
    data-role="grid" 
    data-bind="source: dataSource"> 
    <thead> 
    <tr> 
     <th 
     data-field="ID" 
     data-group-header-template="t_name">ID</th> <!-- Doesn't work! :(--> 
     </tr> 
    </head> 
</table> 

<script> 
    kendo.bind($('body'), viewModel); 
</script> 

如何设置,而不直接调用$.fn.kendoGrid列上的组头模板?

UPDATE:

我检查了剑道电网的源代码,它似乎并没有设置在列定义的所有属性。

作为参考,在Grid._columns ...

// using HTML5 data attributes as a configuration option 
return { 
    field: field, 
    type: type, 
    sortable: sortable !== "false", 
    filterable: filterable !== "false", 
    groupable: groupable !== "false", 
    menu: menu, 
    template: th.attr(kendo.attr("template")), 
    width: cols.eq(idx).css("width") 
}; 

后来,在Grid._groupRowHtml

template = column.groupHeaderTemplate; // Wasn't set in _columns. :(
if (template) { 
    text = typeof template === FUNCTION ? template(data) : kendo.template(template)(data); 
} 

回答

0

编写组一行HTML,当你正确地使用它。然而,属性的内容应该指向包含您的剑道模板的脚本元素的ID。

<script id="myscriptname" type="text/x-kendo-template> 
    <!--script markup/code here--> 
</script> 

<table id="grid" 
    data-role="grid" 
    data-bind="source: dataSource"> 
    <thead> 
    <tr> 
     <th 
     data-field="ID" 
      data-group-header-template="myscriptname">ID</th> 
     </tr> 
    </head> 
</table> 

您还需要呼吁kendo.bind,传递是在DOM层次中的表上方的元素。

+0

我指的是模板ID,我没有在例子中包括它。它仍然不起作用,也没有使用字符串模板:http://jsfiddle.net/Ze2bw/3/。我检查了kendo网格源代码,它似乎没有从任何HTML定义的列中映射页眉或页脚模板;它只映射'template'属性。 – jkappers 2013-05-02 22:33:03

相关问题