Kendo网格,ko绑定以及对行索引的访问 [英] Kendo grid, ko binding, and access to row index
问题描述
我有一个ko视图模型,该模型使用剔除-kendo.js绑定到KendoGrid
I have a ko viewmodel, which I bind to a KendoGrid, using knockout-kendo.js
我使用rowTemplate,因为在某些列(图标,链接等)中需要一些自定义功能
I use rowTemplate, because I need some custom functionality in some columns (icon, links, etc)
我需要基于行号执行一些自定义功能.
I need to do some custom functionality based on rownumber.
当直接绑定ko viewmodel时,我可以使用foreach绑定,并且在行模板中有$ index,它可以为我提供当前行号.
When binding ko viewmodel directly, I can use foreach binding and in the row template I have the $index which gives me the current row number.
当将视图模型绑定到Kendo网格时,我怎么能得到相同的东西?
How can I get the same thing when the viewmodel is bound to a Kendo Grid?
谢谢
推荐答案
当前在Kendo-Knockout模板中没有内置的索引功能支持(在本机Kendo模板中也没有对此的支持).
Currently there is no built in index functionality support in the Kendo-Knockout the templates (also there is no support for this in the native Kendo templates).
不过,您可以结合使用 jQuery的index()
方法和$element
绑定上下文获取数据网格中当前tr
位置的属性(尽管如果使用分页,这将无法正常工作):
However you could use the jQuery's index()
method in combination with the $element
binding context poperty to get the current tr
position inside the datagird (altough this does not work correctly if you using paging):
<div data-bind="kendoGrid: { data: items, rowTemplate: 'rowTmpl',
useKOTemplates: true }"> </div>
<script id="rowTmpl" type="text/html">
<tr>
<td>
Row index:
<span data-bind="text: $($element).closest('tr').index()"></span>
</td>
</tr>
</script>
演示 JSFiddle .
这篇关于Kendo网格,ko绑定以及对行索引的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!