kendo mvvm网格聚合错误

时间:2016-05-22 21:44:54

标签: javascript mvvm kendo-ui datasource

我无法让网格聚合在MVVM中使用kendo ui 我一直收到错误'count is not defined' 我有一个演示here

2 个答案:

答案 0 :(得分:2)

问题不在于聚合,而在于页脚模板。

工作演示here

我参考此question,请参阅未接受的答案,这是您需要的。

答案 1 :(得分:-1)

<div id="example">
    <div data-role="grid" data-row-template="RowTemplate"
        data-columns="[
                        { 'field': 'Name', 'title': 'Name',  'footerTemplate': 'Total'},               
                        { 'field': 'Amount', 'title': 'Amount',  'footerTemplate': '#=kendo.toString(data.Amount ? data.Amount.sum : 0, \'c\')#'}
                      ]"
        data-bind="source: AmountData">
    </div>
</div>
<script id="RowTemplate" type="text/x-kendo-template">   
        <tr>                    
            <td>#= Name # </span></td>          
            <td class="text-right">#if(Amount==0){# #}else{##=kendo.toString(Amount, "c2")##}#</td>          
        </tr>
</script>

<script>
    $(document).ready(function () {
        var viewModel = kendo.observable({

            AmountData: new kendo.data.DataSource({
                type: "Json",
                data: [{ Name: "abc", Amount: 1000 },
                       { Name: "xyz", Amount: 2500 },
                       { Name: "lmn", Amount: 1700 }],
                aggregate: [{ field: "Amount", aggregate: "sum" }]
            })
        });

        kendo.bind($("#example"), viewModel);
    });
</script>