简体   繁体   English

Kendo UI 网格聚合“总和”不起作用

[英]Kendo UI grid aggregation “sum” not working

I exactly followed the examples on Kendo UI's website.我完全按照 Kendo UI 网站上的示例进行操作。 All data shows fine, but all the operation of "sum" not happening.所有数据都显示正常,但“和”的所有操作都没有发生。 So in the groupFooterTemplate, all columns shows the last item in the grid including the "average" column.因此,在 groupFooterTemplate 中,所有列都显示网格中的最后一项,包括“平均”列。 I have been working on this for a few days and just cannot figure out what went wrong.我已经为此工作了几天,只是无法弄清楚出了什么问题。 Did this happen to anyone?有人遇到过这种情况吗?

$scope.vmResyncGridOptions = {
    dataSource: {
        data: $scope.vmDataSource,
        scheme: {
              model: {
                  id: "vmName",
                  fields: {
                      vmName: { type: "string" },
                      vdiskName: { type: "string" },
                      total: { type: "number" },
                      synced: { type: "number" },
                      percent: { type: "number" }
                  }
             }
        },
        group: {
            field: "vmName",
            aggregates: [
                { field: "vdiskName", aggregate: "count" },
                { field: "total", aggregate: "sum" },
                { field: "synced", aggregate: "sum" },
                { field: "percent", aggregate: "average" }
            ]
        },
        aggregate: [
            { field: "vdiskName", aggregate: "count" },
            { field: "total", aggregate: "sum" },
            { field: "synced", aggregate: "sum" },
            { field: "percent", aggregate: "average" }
        ]
      },
      sortable: false,
      scrollable: true,
      pageable: true,
      groupable: true,

      //height: ($scope.screenHeight-110)*0.70-8,
      columns: [
          {
              field: "vdiskName",
              title: $scope.translation.Resync_Table_VDisk_Name,
              aggregates: ["count"],
              groupFooterTemplate: "Count: #=count#"
          },
          {
              field: "total",
              title: $scope.translation.Resync_Table_Total_Bytes,
              aggregates: ["sum"],
              groupFooterTemplate: "Total: #=sum#"
          },
          {
              field: "synced",
              title: $scope.translation.Resync_Table_Has_Resynced,
              aggregates: ["sum"],
              groupFooterTemplate: "Total Resynced: #=sum#"
          },
          {
              field: "percent",
              title: $scope.translation.Resync_Table_VDisck_Completed,
              aggregates: ["average"],
              groupFooterTemplate: "Percent: #=average#"
          }
        ]
    };

Initially check all the table data.最初检查所有表数据。 There is a possibility of spaces or newline characters in the table columns.表列中可能存在空格或换行符。 Even if the columns, which are not aggregated.即使列,也没有聚合。 After the changes recheck the solution.更改后重新检查解决方案。

You group by the same column as the datasource id:您按与数据源 ID 相同的列进行分组:

         id: "vmName",
                  fields: {
                      vmName: { type: "string" },
                      vdiskName: { type: "string" },
                      total: { type: "number" },
                      synced: { type: "number" },
                      percent: { type: "number" }
                  }
             }
        },
        group: {
            field: "vmName",

Thats why you don't get sum and averages.这就是为什么你没有得到总和和平均值。

The issue here is that the data is only cast according to the datasource schema (ie type: "number") during transport operations.这里的问题是数据仅在传输操作期间根据数据源模式(即类型:“数字”)进行转换。 In your case, I'm assuming you're applying the data directly using the Datasource.data([array]) method.在您的情况下,我假设您使用 Datasource.data([array]) 方法直接应用数据。 When you apply the data yourself, the datatypes in your supplied array are preserved.当您自己应用数据时,您提供的数组中的数据类型将被保留。 So, if you pass a numberic value as a string, it will remain as a string in the datasource despite the model indicating that it should be a number.因此,如果您将数字值作为字符串传递,则尽管模型指示它应该是数字,但它仍将作为字符串保留在数据源中。 Numeric data that is cast as a string will not sum;转换为字符串的数字数据不会求和; only the last value will be returned.只会返回最后一个值。 Look at the data you're trying to sum;查看您要汇总的数据; see what datatype it is within the datasource.查看它在数据源中的数据类型。 My guess is that if you're only seeing the last value then your datatype is a string.我的猜测是,如果您只看到最后一个值,那么您的数据类型是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM