Kendo grid, ko binding, and access to row index

拈花ヽ惹草 提交于 2020-01-04 04:15:12

问题


I have a ko viewmodel, which I bind to a KendoGrid, using knockout-kendo.js

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.

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.

How can I get the same thing when the viewmodel is bound to a Kendo Grid?

Thank you


回答1:


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).

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>

Demo JSFiddle.



来源:https://stackoverflow.com/questions/20457426/kendo-grid-ko-binding-and-access-to-row-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!