当导出Kendo Grid时,footerTemplate显示html字符串?

时间:2017-05-19 10:27:28

标签: javascript html kendo-ui kendo-grid

我有footerTemplate的kendo网格。我已成功将此网格导出为Excel。但是那个导出的excel footerTemplate显示了html字符串。

示例网格列:

           {
                field: "January",
                title: "January",
                aggregates: ["sum"],
                filterable: false,
                resourcename: "january",
                type: "currency",
                footerTemplate: function (data) {
                    return "<div style='white-space:initial;float:right'>" + kendo.toString(data.January.sum, "n0") + "</div>";
                }
            }

图片:enter image description here

问题:      如何修复这个html字符串问题??

感谢.......

1 个答案:

答案 0 :(得分:3)

确保您的dataSource包含您希望获得sum的列的sum aggregate功能:

dataSource: {
  data: [
    { item: "AB", january: 12.24 },
    { item: "CD", january: 22.23 }
  ],
  aggregate: [
    { field: "january", aggregate: "sum" }        
  ]
}

然后在要显示值的列上声明您的footerTemplate

columns: [
  { field: "item" },
  { field: "january",
    type: "currency",
    footerTemplate: "Sum: #: sum #"
  }
]

完整的Dojo工作示例here

编辑 - 右对齐footerTemplate

中的内容

网格:

footerTemplate: "<div style='text-align: right'>Sum: #: sum #</div>"

Excel导出 - 在网格定义中包含以下excelExport函数:

excelExport: function(e) {
    var rows = e.workbook.sheets[0].rows;

    for (var ri = 0; ri < rows.length; ri++) {
      var row = rows[ri];

      if (row.type == "group-footer" || row.type == "footer") {
        for (var ci = 0; ci < row.cells.length; ci++) {
          var cell = row.cells[ci];
          if (cell.value) {                
            cell.value = $(cell.value).text();
            // Set the alignment
            cell.hAlign = "right";
          }
        }
      }
    }
  }

hAlign是设置为对齐文字的属性,但是如果使用Kendo版本2015.3 /更新版本,则不推荐使用此属性,因此请改用textAlign

我还更新了Dojo example以反映这些变化。