动态列上的kendogrid聚合

时间:2014-12-02 12:30:37

标签: kendo-grid

我正在使用ASP.NET webmethodsKendoGrid将数据绑定到Grid。生成的列是动态的。我需要在每列上应用aggregate。请让我知道如何实现这一目标。

我不会知道来自WebMethod的列名。所以不确定如何编写聚合。我认为一旦加载了网格,我们就可以访问它然后定义聚合。请指导。用Google搜索但没有得到任何帮助。

aggregate: [{field: "unknowncolumnnames", aggregate: "sum" }]

 $.ajax({
    url: "Details.aspx/DetailsWebMethod",
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    success: function (data) {
         $("#DetailsGrid").kendoGrid({

                dataSource: {
                    type: "json",
                    data: data.Table,
                    pageSize: 10
                },
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
                pageable: {
                    input: true,
                    pageSizes: true,
                    numeric: false
                },

                selectable: "row",
                filterable: true,
                columnMenu: true,
                navigatable: true,
                reorderable: true,
                resizable: true,
                groupable: false,
                scrollable: false
            });
         }
     });

1 个答案:

答案 0 :(得分:2)

            $.ajax({
            url: "",
            datatype: "JSON",
            type: "GET",
            success: function (result) {
                var items = $.parseJSON(result)[0];
                var arrCol = [];
                var arrAgg = [];
                for (var index in items) 
                {
                    arrCol.push({ field: index, format: "{0:0}",  footerTemplate: "#= kendo.toString(sum, '0.00') #" });
                    arrAgg.push({ field: index, aggregate: "sum" });
                }
                console.log(arrAgg);
                if (result.Result.length > 0) {
                    var dataSource = new kendo.data.DataSource({
                        data: $.parseJSON(result.Result),
                        group: { field: "Category" },
                        aggregate: arrAgg
                    });
                    $('#divgrid').html("");
                    $("#divgrid").kendoGrid({
                        dataSource: dataSource,
                        height: "auto",
                        scrollable: false,
                        sortable: true,
                        groupable: false,
                        columns: arrCol
                    });